apple_clis/codesign/display/
output.rs1use crate::prelude::*;
2
3pub use self::signed_keys::SignedKeys;
4mod signed_keys;
5
6#[derive(Debug, Serialize)]
7#[non_exhaustive]
8#[must_use = include_doc!(must_use_cmd_output)]
9pub enum DisplayOutput {
10 NotSignedAtAll {
12 path: Utf8PathBuf,
13 },
14
15 SignedKeys(signed_keys::SignedKeys),
17
18 #[doc = include_doc!(cmd_success)]
19 SuccessUnimplemented {
20 stdout: String,
21 },
22
23 #[doc = include_doc!(cmd_error)]
24 ErrorUnImplemented {
25 stderr: String,
26 },
27}
28
29impl CommandNomParsable for DisplayOutput {
30 fn success_unimplemented(str: String) -> Self {
31 Self::SuccessUnimplemented { stdout: str }
32 }
33
34 fn error_unimplemented(str: String) -> Self {
35 Self::ErrorUnImplemented { stderr: str }
36 }
37
38 fn success_nom_from_str(input: &str) -> IResult<&str, Self> {
39 alt((
40 parse_key_value,
41 map_res(rest, |s| {
42 SignedKeys::from_raw(s).map(DisplayOutput::SignedKeys)
43 }),
44 ))(input)
45 }
46}
47
48impl PublicCommandOutput for DisplayOutput {
49 type PrimarySuccess = signed_keys::SignedKeys;
50
51 fn success(&self) -> Result<&Self::PrimarySuccess> {
52 match self {
53 DisplayOutput::SignedKeys(keys) => Ok(keys),
54 _ => Err(Error::output_errored(self)),
55 }
56 }
57}
58
59fn parse_key_value(input: &str) -> IResult<&str, DisplayOutput> {
60 let (remaining, path) = map(
61 terminated(take_while(|c| c != ':'), tag(": ")),
62 Utf8Path::new,
63 )(input)?;
64 map(ws(tag("code object is not signed at all")), move |_| {
65 debug!("Parsed NotSignedAtAll");
66 DisplayOutput::NotSignedAtAll {
67 path: path.to_owned(),
68 }
69 })(remaining)
70}