@@ -69,7 +69,7 @@ public bool Verify(ReadOnlySpan<byte> data, ReadOnlySpan<byte> signature)
6969 return _type switch
7070 {
7171 COSEKeyType . EC2 => _ecdsa ! . VerifyData ( data , signature , HashAlgFromCOSEAlg ( _alg ) , DSASignatureFormat . Rfc3279DerSequence ) ,
72- COSEKeyType . RSA => _rsa ! . VerifyData ( data , signature , HashAlgFromCOSEAlg ( _alg ) , Padding ) ,
72+ COSEKeyType . RSA => _rsa ! . VerifyData ( data , signature , HashAlgFromCOSEAlg ( _alg ) , GetRSASignaturePadding ( ) ) ,
7373 _ => throw new InvalidOperationException ( $ "Missing or unknown kty { _type } ") ,
7474 } ;
7575 }
@@ -159,31 +159,29 @@ static bool IsValidKtyCrvCombination(COSEKeyType kty, COSEEllipticCurve crv)
159159 }
160160 }
161161
162- internal RSASignaturePadding Padding
162+ private RSASignaturePadding GetRSASignaturePadding ( )
163163 {
164- get
164+ if ( _type != COSEKeyType . RSA )
165165 {
166- if ( _type != COSEKeyType . RSA )
167- {
168- throw new InvalidOperationException ( $ "Must be a RSA key. Was { _type } ") ;
169- }
170-
171- switch ( _alg ) // https://www.iana.org/assignments/cose/cose.xhtml#algorithms
172- {
173- case COSEAlgorithmIdentifier . PS256 :
174- case COSEAlgorithmIdentifier . PS384 :
175- case COSEAlgorithmIdentifier . PS512 :
176- return RSASignaturePadding . Pss ;
177-
178- case COSEAlgorithmIdentifier . RS1 :
179- case COSEAlgorithmIdentifier . RS256 :
180- case COSEAlgorithmIdentifier . RS384 :
181- case COSEAlgorithmIdentifier . RS512 :
182- return RSASignaturePadding . Pkcs1 ;
183- default :
184- throw new InvalidOperationException ( $ "Missing or unknown alg { _alg } ") ;
185- }
166+ throw new InvalidOperationException ( $ "Cannot get RSA signature padding for key type { _type } .") ;
186167 }
168+
169+ // https://www.iana.org/assignments/cose/cose.xhtml#algorithms
170+ return _alg switch
171+ {
172+ COSEAlgorithmIdentifier . PS256 or
173+ COSEAlgorithmIdentifier . PS384 or
174+ COSEAlgorithmIdentifier . PS512
175+ => RSASignaturePadding . Pss ,
176+
177+ COSEAlgorithmIdentifier . RS1 or
178+ COSEAlgorithmIdentifier . RS256 or
179+ COSEAlgorithmIdentifier . RS384 or
180+ COSEAlgorithmIdentifier . RS512
181+ => RSASignaturePadding . Pkcs1 ,
182+
183+ _ => throw new InvalidOperationException ( $ "Missing or unknown alg { _alg } ") ,
184+ } ;
187185 }
188186
189187 private static HashAlgorithmName HashAlgFromCOSEAlg ( COSEAlgorithmIdentifier alg )
0 commit comments