@@ -125,38 +125,39 @@ impl KMSSigner {
125125 let config = aws_config:: load_from_env ( ) . await ;
126126 let client = aws_sdk_kms:: Client :: new ( & config) ;
127127 let arn = aws_arn:: ResourceName :: from_str ( & arn_string) ?;
128- Ok ( KMSSigner {
128+ let mut signer = KMSSigner {
129129 client,
130130 arn,
131131 public_key : None ,
132- } )
133- }
132+ } ;
134133
135- pub async fn get_and_cache_public_key ( & mut self ) -> anyhow :: Result < ( ) > {
136- let ( public_key, pubkey_evm) = self . get_public_key ( ) . await ? ;
137- self . public_key = Some ( ( public_key , pubkey_evm ) ) ;
138- Ok ( ( ) )
134+ let ( public_key , pubkey_evm ) = signer . get_public_key ( ) . await ? ;
135+ signer . public_key = Some ( ( public_key, pubkey_evm) ) ;
136+
137+ Ok ( signer )
139138 }
140139}
141140
141+ // Use DER (Distinguished Encoding Rules) format to encode the public key and the signature.
142+ // - When retrieving the public key from AWS KMS using the GetPublicKey API
143+ // (https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html),
144+ // note that the returned public key is DER-encoded in the SubjectPublicKeyInfo format,
145+ // compliant with RFC 5280 / X.509 standards.
146+ // - When signing messages with ECDSA using the AWS KMS Sign API
147+ // (https://docs.aws.amazon.com/kms/latest/APIReference/API_Sign.html),
148+ // the returned signature is a DER-encoded ASN.1 sequence containing the r and s values.
149+
142150/// X.509 `AlgorithmIdentifier` (same as above)
143- #[ derive( Copy , Clone , Debug , Eq , PartialEq , Sequence ) ] // NOTE: added `Sequence`
151+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Sequence ) ]
144152pub struct AlgorithmIdentifier < ' a > {
145- /// This field contains an ASN.1 `OBJECT IDENTIFIER`, a.k.a. OID.
146153 pub algorithm : ObjectIdentifier ,
147-
148- /// This field is `OPTIONAL` and contains the ASN.1 `ANY` type, which
149- /// in this example allows arbitrary algorithm-defined parameters.
150154 pub parameters : Option < AnyRef < ' a > > ,
151155}
152156
153157/// X.509 `SubjectPublicKeyInfo` (SPKI)
154158#[ derive( Copy , Clone , Debug , Eq , PartialEq , Sequence ) ]
155159pub struct SubjectPublicKeyInfo < ' a > {
156- /// X.509 `AlgorithmIdentifier`
157160 pub algorithm : AlgorithmIdentifier < ' a > ,
158-
159- /// Public key data
160161 pub subject_public_key : BitStringRef < ' a > ,
161162}
162163
0 commit comments