Skip to content

Commit 2f29200

Browse files
committed
m
1 parent 3989801 commit 2f29200

File tree

5 files changed

+400
-6
lines changed

5 files changed

+400
-6
lines changed

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ aws-mpl-primitives = { path = "/Users/ajewell/esdk_rust/prim" }
1313
derivative = "2.2.0"
1414
derive_builder = "0.20.2"
1515

16-
clap = { version = "4.5.49", features = ["derive"], optional = true }
16+
clap = { version = "4.5.50", features = ["derive"], optional = true }
1717
serde_json = { version = "1.0.145", optional = true }
1818
anyhow = { version = "1.0.100", optional = true }
1919
base64 = { version = "0.22.1", optional = true }
@@ -38,5 +38,6 @@ path = "src/bin/test_vector/main.rs"
3838
required-features = ["test_vectors"] # Only build binary when cli feature is enabled
3939

4040
[features]
41-
default = []
41+
# default = []
42+
default = ["test_vectors"]
4243
test_vectors = ["clap", "serde_json", "anyhow", "base64", "aws-sdk-kms", "aws-config"] # Users can enable with --features test_vectors
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
use std::backtrace::Backtrace;
2+
3+
#[derive(Clone, PartialEq, Eq, Debug)]
4+
#[non_exhaustive]
5+
/// Individual error types for ESDK
6+
pub enum ErrorKind {
7+
/// Higher level ESDK errors
8+
Esdk(String),
9+
/// Error in serializing or deserializing the data
10+
SerializationError(String),
11+
/// Low level cryptographic error from `aws_mpl_primitives`
12+
CryptographicError(String),
13+
/// Low level cryptographic error from `aws_mpl_rs::aws_cryptography_primitives`
14+
PrimitivesError(aws_mpl_rs::deps::aws_cryptography_primitives::types::error::Error),
15+
/// Mid level cryptographic error from `aws_mpl_rs`
16+
MplError(Box<aws_mpl_rs::types::error::Error>),
17+
/// Malformed input. No cryptography has been attempted.
18+
ValidationError(String),
19+
}
20+
#[derive(Debug)]
21+
#[non_exhaustive]
22+
/// Base error type for ESDK
23+
pub struct Error {
24+
/// Error type
25+
pub kind: ErrorKind,
26+
/// Backtrace captured when error was encountered.
27+
/// For `MplError` and `PrimitivesError`, the backtrace is not captured until the ESDK level
28+
pub backtrace: Backtrace,
29+
/// The Error causing the Error, if any.
30+
pub cause: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
31+
}
32+
33+
impl std::fmt::Display for Error {
34+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35+
match &self.kind {
36+
ErrorKind::Esdk(message) => write!(f, "Esdk Error {message}"),
37+
ErrorKind::SerializationError(message) => write!(f, "Serialization Error {message}"),
38+
ErrorKind::CryptographicError(message) => write!(f, "Cryptographic Error {message}"),
39+
ErrorKind::PrimitivesError(message) => write!(f, "Primitives Error {message}"),
40+
ErrorKind::MplError(message) => write!(f, "MPL Error {message}"),
41+
ErrorKind::ValidationError(message) => write!(f, "Validation Error {message}"),
42+
}
43+
}
44+
}
45+
46+
pub(crate) fn val_err(msg: impl Into<String>) -> Error {
47+
Error {
48+
kind: ErrorKind::ValidationError(msg.into()),
49+
backtrace: Backtrace::capture(),
50+
cause: None,
51+
}
52+
}
53+
54+
impl std::error::Error for Error {
55+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
56+
match &self.cause {
57+
Some(cause) => Some(cause.as_ref()),
58+
None => None,
59+
}
60+
}
61+
}
62+
63+
impl From<aws_mpl_rs::deps::aws_cryptography_primitives::types::error::Error> for Error {
64+
fn from(item: aws_mpl_rs::deps::aws_cryptography_primitives::types::error::Error) -> Self {
65+
Self {
66+
kind: ErrorKind::PrimitivesError(item),
67+
backtrace: Backtrace::capture(),
68+
cause: None,
69+
}
70+
}
71+
}
72+
73+
impl From<aws_mpl_rs::types::error::Error> for Error {
74+
#[track_caller]
75+
fn from(item: aws_mpl_rs::types::error::Error) -> Self {
76+
Self {
77+
kind: ErrorKind::MplError(Box::new(item)),
78+
backtrace: Backtrace::capture(),
79+
cause: None,
80+
}
81+
}
82+
}
83+
84+
impl From<aws_mpl_primitives::Error> for Error {
85+
#[track_caller]
86+
fn from(item: aws_mpl_primitives::Error) -> Self {
87+
Self {
88+
kind: ErrorKind::CryptographicError(item.msg),
89+
backtrace: item.backtrace,
90+
cause: None,
91+
}
92+
}
93+
}
94+
95+
impl From<aws_smithy_types::error::operation::BuildError> for Error {
96+
fn from(item: aws_smithy_types::error::operation::BuildError) -> Self {
97+
Self {
98+
kind: ErrorKind::ValidationError(format!("{item:?}")),
99+
backtrace: Backtrace::capture(),
100+
cause: Some(Box::new(item)),
101+
}
102+
}
103+
}
104+
105+
impl From<&str> for Error {
106+
fn from(item: &str) -> Self {
107+
Self {
108+
kind: ErrorKind::Esdk(item.to_string()),
109+
backtrace: Backtrace::capture(),
110+
cause: None,
111+
}
112+
}
113+
}
114+
115+
impl From<String> for Error {
116+
fn from(item: String) -> Self {
117+
Self {
118+
kind: ErrorKind::Esdk(item),
119+
backtrace: Backtrace::capture(),
120+
cause: None,
121+
}
122+
}
123+
}
124+
125+
impl From<derive_builder::UninitializedFieldError> for Error {
126+
fn from(item: derive_builder::UninitializedFieldError) -> Self {
127+
Self {
128+
kind: ErrorKind::ValidationError(format!("{item}")),
129+
backtrace: Backtrace::capture(),
130+
cause: None,
131+
}
132+
}
133+
}

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/src/esdk_operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Client {
9393
&self.config,
9494
plaintext,
9595
ciphertext,
96-
0,
96+
input.data_size.unwrap_or(usize::MAX),
9797
input.materials_manager.clone(),
9898
input.keyring.clone(),
9999
input.encryption_context,

AwsEncryptionSDK/runtimes/rust/esdk_rust/esdk/src/test_vectors/do_decrypt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,21 @@ pub(crate) async fn run_decrypt_tests(
435435
let esdk = crate::client::Client::from_conf(esdk_config)?;
436436
let kms = make_kms_map().await;
437437
let mut res = TestResults::default();
438+
let mut num_non = 0;
438439
for test in tests {
439440
res.total += 1;
440441
if test.decrypt_key_description.kind == "aws-kms-hierarchy" {
441442
res.skipped += 1;
442443
} else if test.decrypt_key_description.kind == "aws-kms-ecdh" {
443444
res.skipped += 1;
444-
} else if test.decrypt_key_description.kind != "raw" {
445+
} else if test.decrypt_key_description.kind == "unknown" {
445446
res.skipped += 1;
446-
} else if test.decrypt_key_description.kind.is_empty() {
447-
println!("XXXXXXXXXXXXXX EMPTY XXXXXXXXXX");
447+
} else if test.decrypt_key_description.kind != "raw" && num_non > 5 {
448448
res.skipped += 1;
449449
} else {
450+
if test.decrypt_key_description.kind != "raw" {
451+
num_non += 1;
452+
}
450453
let cmm = get_cmm(&test.decrypt_key_description, keys, &mpl, &kms).await?;
451454
match run_decrypt_test(&esdk, test, cmm, dir).await {
452455
Ok(()) => {

0 commit comments

Comments
 (0)