Skip to content

Commit 3f0fe3f

Browse files
yalemandacut
authored andcommitted
fix: add test, define static value for reuse
1 parent 0a70ff1 commit 3f0fe3f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/signing_key.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ use {
1717
/// String included at the end of the AWS SigV4 credential scope
1818
const AWS4_REQUEST: &str = "aws4_request";
1919

20+
/// The default length of an AWS secret key, including the "AWS4" prefix.
21+
pub(crate) static KSECRETKEY_LENGTH: usize = 44;
22+
2023
/// A raw AWS secret key (`kSecret`).
2124
#[derive(Clone, Copy, PartialEq, Eq)]
22-
pub struct KSecretKey<const M: usize = 44> {
25+
pub struct KSecretKey<const M: usize = KSECRETKEY_LENGTH> {
2326
/// The secret key, prefixed with "AWS4".
2427
prefixed_key: [u8; M],
2528

@@ -395,7 +398,7 @@ where
395398
#[cfg(test)]
396399
mod tests {
397400
use {
398-
crate::{GetSigningKeyRequest, GetSigningKeyResponse, KSecretKey},
401+
crate::{GetSigningKeyRequest, GetSigningKeyResponse, KSecretKey, KSECRETKEY_LENGTH},
399402
chrono::NaiveDate,
400403
scratchstack_aws_principal::{AssumedRole, Principal},
401404
std::str::FromStr,
@@ -554,4 +557,14 @@ mod tests {
554557
assert!(response.principal().is_empty());
555558
assert!(response.session_data().is_empty());
556559
}
560+
561+
#[test]
562+
fn test_key_from_str_length() {
563+
assert_eq!(KSecretKey::from_str("123"), Err(crate::KeyLengthError::TooShort));
564+
assert_eq!(
565+
KSecretKey::from_str("123456789012345678901234567890123456789012345"),
566+
Err(crate::KeyLengthError::TooLong)
567+
);
568+
assert!(KSecretKey::<KSECRETKEY_LENGTH>::from_str("1234567890123456789012345678901234567890").is_ok());
569+
}
557570
}

0 commit comments

Comments
 (0)