1*fb441a64SWill Schurman // Copyright 2015-present 650 Industries. All rights reserved.
2*fb441a64SWill Schurman 
3*fb441a64SWill Schurman // swiftlint:disable identifier_name
4*fb441a64SWill Schurman 
5*fb441a64SWill Schurman import Foundation
6*fb441a64SWill Schurman 
7*fb441a64SWill Schurman internal enum CodeSigningError: Error {
8*fb441a64SWill Schurman   case CertificateEncodingError
9*fb441a64SWill Schurman   case CertificateDERDecodeError
10*fb441a64SWill Schurman   case CertificateValidityError
11*fb441a64SWill Schurman   case CertificateMissingPublicKeyError
12*fb441a64SWill Schurman   case CertificateDigitalSignatureNotPresentError
13*fb441a64SWill Schurman   case CertificateMissingCodeSigningError
14*fb441a64SWill Schurman   case CertificateRootNotCA
15*fb441a64SWill Schurman   case CertificateProjectInformationChainError
16*fb441a64SWill Schurman   case KeyIdMismatchError
17*fb441a64SWill Schurman   case SecurityFrameworkError
18*fb441a64SWill Schurman   case CertificateEmptyError
19*fb441a64SWill Schurman   case CertificateChainError
20*fb441a64SWill Schurman   case CertificateRootNotSelfSigned
21*fb441a64SWill Schurman   case SignatureHeaderMissing
22*fb441a64SWill Schurman   case SignatureHeaderStructuredFieldParseError
23*fb441a64SWill Schurman   case SignatureHeaderSigMissing
24*fb441a64SWill Schurman   case SignatureHeaderSignatureEncodingError
25*fb441a64SWill Schurman   case SignatureEncodingError
26*fb441a64SWill Schurman   case AlgorithmParseError
27*fb441a64SWill Schurman   case InvalidExpoProjectInformationExtensionValue
28*fb441a64SWill Schurman 
messagenull29*fb441a64SWill Schurman   func message() -> String {
30*fb441a64SWill Schurman     switch self {
31*fb441a64SWill Schurman     case .CertificateEncodingError:
32*fb441a64SWill Schurman       return "Code signing certificate could not be encoded in a lossless manner using utf8 encoding"
33*fb441a64SWill Schurman     case .CertificateDERDecodeError:
34*fb441a64SWill Schurman       return "Code signing certificate data not in DER format"
35*fb441a64SWill Schurman     case .CertificateMissingPublicKeyError:
36*fb441a64SWill Schurman       return "Code signing certificate missing public key"
37*fb441a64SWill Schurman     case .CertificateValidityError:
38*fb441a64SWill Schurman       return "Certificate not valid"
39*fb441a64SWill Schurman     case .CertificateDigitalSignatureNotPresentError:
40*fb441a64SWill Schurman       return "Certificate digital signature not present"
41*fb441a64SWill Schurman     case .CertificateMissingCodeSigningError:
42*fb441a64SWill Schurman       return "Certificate missing code signing extended key usage"
43*fb441a64SWill Schurman     case .CertificateRootNotCA:
44*fb441a64SWill Schurman       return "Root certificate subject must be a Certificate Authority"
45*fb441a64SWill Schurman     case .CertificateProjectInformationChainError:
46*fb441a64SWill Schurman       return "Expo project information must be a subset or equal of that of parent certificates"
47*fb441a64SWill Schurman     case .KeyIdMismatchError:
48*fb441a64SWill Schurman       return "Key with keyid from signature not found in client configuration"
49*fb441a64SWill Schurman     case .SecurityFrameworkError:
50*fb441a64SWill Schurman       return "Signature verification failed due to security framework error"
51*fb441a64SWill Schurman     case .CertificateEmptyError:
52*fb441a64SWill Schurman       return "No code signing certificates provided"
53*fb441a64SWill Schurman     case .CertificateChainError:
54*fb441a64SWill Schurman       return "Certificate chain error"
55*fb441a64SWill Schurman     case .CertificateRootNotSelfSigned:
56*fb441a64SWill Schurman       return "Root certificate not self-signed"
57*fb441a64SWill Schurman     case .SignatureHeaderMissing:
58*fb441a64SWill Schurman       return "No expo-signature header specified"
59*fb441a64SWill Schurman     case .SignatureHeaderStructuredFieldParseError:
60*fb441a64SWill Schurman       return "expo-signature structured header parsing failed"
61*fb441a64SWill Schurman     case .SignatureHeaderSigMissing:
62*fb441a64SWill Schurman       return "Structured field sig not found in expo-signature header"
63*fb441a64SWill Schurman     case .SignatureHeaderSignatureEncodingError:
64*fb441a64SWill Schurman       return "Signature in header has invalid encoding"
65*fb441a64SWill Schurman     case .SignatureEncodingError:
66*fb441a64SWill Schurman       return "Invalid signature encoding"
67*fb441a64SWill Schurman     case .AlgorithmParseError:
68*fb441a64SWill Schurman       return "Invalid algorithm"
69*fb441a64SWill Schurman     case .InvalidExpoProjectInformationExtensionValue:
70*fb441a64SWill Schurman       return "Invalid Expo project information extension value"
71*fb441a64SWill Schurman     }
72*fb441a64SWill Schurman   }
73*fb441a64SWill Schurman }
74