@@ -125,38 +125,39 @@ impl KMSSigner {
125
125
let config = aws_config:: load_from_env ( ) . await ;
126
126
let client = aws_sdk_kms:: Client :: new ( & config) ;
127
127
let arn = aws_arn:: ResourceName :: from_str ( & arn_string) ?;
128
- Ok ( KMSSigner {
128
+ let mut signer = KMSSigner {
129
129
client,
130
130
arn,
131
131
public_key : None ,
132
- } )
133
- }
132
+ } ;
134
133
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 )
139
138
}
140
139
}
141
140
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
+
142
150
/// 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 ) ]
144
152
pub struct AlgorithmIdentifier < ' a > {
145
- /// This field contains an ASN.1 `OBJECT IDENTIFIER`, a.k.a. OID.
146
153
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.
150
154
pub parameters : Option < AnyRef < ' a > > ,
151
155
}
152
156
153
157
/// X.509 `SubjectPublicKeyInfo` (SPKI)
154
158
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Sequence ) ]
155
159
pub struct SubjectPublicKeyInfo < ' a > {
156
- /// X.509 `AlgorithmIdentifier`
157
160
pub algorithm : AlgorithmIdentifier < ' a > ,
158
-
159
- /// Public key data
160
161
pub subject_public_key : BitStringRef < ' a > ,
161
162
}
162
163
0 commit comments