|
17 | 17 | /// String included at the end of the AWS SigV4 credential scope |
18 | 18 | const AWS4_REQUEST: &str = "aws4_request"; |
19 | 19 |
|
| 20 | +/// The default length of an AWS secret key, including the "AWS4" prefix. |
| 21 | +pub(crate) static KSECRETKEY_LENGTH: usize = 44; |
| 22 | + |
20 | 23 | /// A raw AWS secret key (`kSecret`). |
21 | 24 | #[derive(Clone, Copy, PartialEq, Eq)] |
22 | | -pub struct KSecretKey<const M: usize = 44> { |
| 25 | +pub struct KSecretKey<const M: usize = KSECRETKEY_LENGTH> { |
23 | 26 | /// The secret key, prefixed with "AWS4". |
24 | 27 | prefixed_key: [u8; M], |
25 | 28 |
|
@@ -395,7 +398,7 @@ where |
395 | 398 | #[cfg(test)] |
396 | 399 | mod tests { |
397 | 400 | use { |
398 | | - crate::{GetSigningKeyRequest, GetSigningKeyResponse, KSecretKey}, |
| 401 | + crate::{GetSigningKeyRequest, GetSigningKeyResponse, KSecretKey, KSECRETKEY_LENGTH}, |
399 | 402 | chrono::NaiveDate, |
400 | 403 | scratchstack_aws_principal::{AssumedRole, Principal}, |
401 | 404 | std::str::FromStr, |
@@ -554,4 +557,14 @@ mod tests { |
554 | 557 | assert!(response.principal().is_empty()); |
555 | 558 | assert!(response.session_data().is_empty()); |
556 | 559 | } |
| 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 | + } |
557 | 570 | } |
0 commit comments