Skip to content

Commit b2d5381

Browse files
committed
Address comments
1 parent 0f8a3f8 commit b2d5381

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/main.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ async fn run_listener(input: RunListenerInput) -> Result<(), PubsubClientError>
174174

175175
async fn get_signer(run_options: config::RunOptions) -> anyhow::Result<Arc<dyn Signer>> {
176176
let scheme = run_options.signer_uri.split("://").next().unwrap_or("");
177-
println!("Using signer URI: {}", scheme);
178177
match scheme {
179178
"file" => {
180179
let signer = signer::FileSigner::try_new(
@@ -193,12 +192,7 @@ async fn get_signer(run_options: config::RunOptions) -> anyhow::Result<Arc<dyn S
193192
.as_str()
194193
.strip_prefix("amazonkms://")
195194
.ok_or_else(|| anyhow::anyhow!("Invalid Amazon KMS ARN in signer URI"))?;
196-
println!("Using Amazon KMS signer with ARN: {}", arn_string);
197-
let mut signer = signer::KMSSigner::try_new(arn_string.to_string()).await?;
198-
signer
199-
.get_and_cache_public_key()
200-
.await
201-
.map_err(|e| anyhow::anyhow!("Failed to get public key: {}", e))?;
195+
let signer = signer::KMSSigner::try_new(arn_string.to_string()).await?;
202196
Ok(Arc::new(signer))
203197
}
204198
_ => Err(anyhow::anyhow!("Unsupported signer URI scheme")),

src/signer.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
144152
pub 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)]
155159
pub 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

Comments
 (0)