@@ -116,9 +116,23 @@ pub const Parsed = struct {
116116 return p .slice (p .message_slice );
117117 }
118118
119+ pub const VerifyError = error {
120+ CertificateIssuerMismatch ,
121+ CertificateNotYetValid ,
122+ CertificateExpired ,
123+ CertificateSignatureAlgorithmUnsupported ,
124+ CertificateSignatureAlgorithmMismatch ,
125+ CertificateFieldHasInvalidLength ,
126+ CertificateFieldHasWrongDataType ,
127+ CertificatePublicKeyInvalid ,
128+ CertificateSignatureInvalidLength ,
129+ CertificateSignatureInvalid ,
130+ CertificateSignatureUnsupportedBitCount ,
131+ };
132+
119133 /// This function checks the time validity for the subject only. Checking
120134 /// the issuer's time validity is out of scope.
121- pub fn verify (parsed_subject : Parsed , parsed_issuer : Parsed ) ! void {
135+ pub fn verify (parsed_subject : Parsed , parsed_issuer : Parsed ) VerifyError ! void {
122136 // Check that the subject's issuer name matches the issuer's
123137 // subject name.
124138 if (! mem .eql (u8 , parsed_subject .issuer (), parsed_issuer .subject ())) {
@@ -452,11 +466,19 @@ fn verifyRsa(
452466 hash_der ++
453467 msg_hashed ;
454468
455- const public_key = try rsa .PublicKey .fromBytes (exponent , modulus , rsa .poop );
456- const em_dec = try rsa .encrypt (modulus_len , sig [0.. modulus_len ].* , public_key , rsa .poop );
469+ const public_key = rsa .PublicKey .fromBytes (exponent , modulus , rsa .poop ) catch | err | switch (err ) {
470+ error .OutOfMemory = > @panic ("TODO don't heap allocate" ),
471+ };
472+ const em_dec = rsa .encrypt (modulus_len , sig [0.. modulus_len ].* , public_key , rsa .poop ) catch | err | switch (err ) {
473+ error .OutOfMemory = > @panic ("TODO don't heap allocate" ),
474+
475+ error .MessageTooLong = > unreachable ,
476+ error .NegativeIntoUnsigned = > @panic ("TODO make RSA not emit this error" ),
477+ error .TargetTooSmall = > @panic ("TODO make RSA not emit this error" ),
478+ error .BufferTooSmall = > @panic ("TODO make RSA not emit this error" ),
479+ };
457480
458481 if (! mem .eql (u8 , & em , & em_dec )) {
459- try std .testing .expectEqualSlices (u8 , & em , & em_dec );
460482 return error .CertificateSignatureInvalid ;
461483 }
462484 },
0 commit comments