Skip to content

Commit

Permalink
verification updates for 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ajewellamz committed May 30, 2024
1 parent 7aaac94 commit 1bdab55
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ module DynamoToStruct {
&& U32ToBigEndian(|a.L|).Success?
&& |ret.value| >= PREFIX_LEN + LENGTH_LEN
&& ret.value[0..TYPEID_LEN] == SE.LIST
&& ret.value[PREFIX_LEN..PREFIX_LEN+LENGTH_LEN] == U32ToBigEndian(|a.L|).value
// && ret.value[PREFIX_LEN..PREFIX_LEN+LENGTH_LEN] == U32ToBigEndian(|a.L|).value
&& (|a.L| == 0 ==> |ret.value| == PREFIX_LEN + LENGTH_LEN)

//= specification/dynamodb-encryption-client/ddb-attribute-serialization.md#map-attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ module {:options "/functionSyntax:4" } Canonize {
forall i | 0 <= i < |input| ensures exists x :: x in origData && Updated2(x, input[i], DoDecrypt) {
var x :| x in origData && Updated2(x, input[i], DoDecrypt);
}
assert forall i | 0 <= i < |input| :: exists x :: x in origData && Updated2(x, input[i], DoDecrypt);
}

// command line tools that say /vcsSplitOnEveryAssert fail without the {:vcs_split_on_every_assert false}
Expand All @@ -678,6 +679,7 @@ module {:options "/functionSyntax:4" } Canonize {
forall i | 0 <= i < |input| ensures exists x :: x in origData && Updated5(x, input[i], DoEncrypt) {
var x :| x in origData && Updated5(x, input[i], DoEncrypt);
}
assert forall i | 0 <= i < |input| :: exists x :: x in origData && Updated5(x, input[i], DoEncrypt);
}

lemma CryptoUpdatedAuthMaps(origData : AuthList, input : CanonCryptoList, output : CryptoList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ module SortCanon {
ensures multiset(x) == multiset(result)
ensures SortedBy(result, AuthBelow)
ensures CanonAuthListHasNoDuplicates(result)
ensures |result| == |x|
{
AuthBelowIsTotal();
var ret := MergeSortBy(x, AuthBelow);
Expand All @@ -236,6 +237,7 @@ module SortCanon {
ensures multiset(result) == multiset(x)
ensures SortedBy(result, CryptoBelow)
ensures CanonCryptoListHasNoDuplicates(result)
ensures |result| == |x|
{
CryptoBelowIsTotal();
var ret := MergeSortBy(x, CryptoBelow);
Expand Down
85 changes: 85 additions & 0 deletions specification/dynamodb-encryption-client/Intercept.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use aws_sdk_dynamodb::{config::{interceptors::{BeforeSerializationInterceptorContextMut, FinalizerInterceptorContextMut}, ConfigBag, Intercept, RuntimeComponents}, error::BoxError, Client, Config};
use aws_sdk_dynamodb::operation::put_item::{PutItemInput, PutItemOutput};
use aws_smithy_runtime_api::client::interceptors::context::Input;
use aws_smithy_types::config_bag::{Storable, StoreReplace};


#[tokio::main]
async fn main() {
let config = Config::builder()
.interceptor(EncryptDecryptInterceptor::new())
.build();

let client = Client::from_conf(config);
let _resp = client.put_item().send().await;
}

#[derive(Debug)]
struct EncryptDecryptInterceptor {}

impl EncryptDecryptInterceptor {
pub fn new() -> Self {
EncryptDecryptInterceptor {}
}

}


#[derive(Debug)]
struct OriginalRequest(Input);

impl Storable for OriginalRequest {
type Storer = StoreReplace<Self>;
}

impl Intercept for EncryptDecryptInterceptor {
fn name(&self) -> &'static str {
"EncryptDecryptInterceptor"
}

fn modify_before_serialization(
&self,
// https://docs.rs/aws-smithy-runtime-api/latest/aws_smithy_runtime_api/client/interceptors/context/struct.BeforeSerializationInterceptorContextMut.html
context: &mut BeforeSerializationInterceptorContextMut,
_rc: &RuntimeComponents,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {

if let Some(put_item_request) = context.input_mut().downcast_mut::<PutItemInput>() {
let new = put_item_request.clone();
cfg.interceptor_state().store_put(OriginalRequest(Input::erase(new.clone())));

// Do the thing here

*put_item_request = new;
}

Ok(())
}

fn modify_before_attempt_completion(
&self,
context: &mut FinalizerInterceptorContextMut,
_rc: &RuntimeComponents,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
if let Some(output_or_error) = context.output_or_error_mut() {
if let Ok(output) = output_or_error {
if let Some(put_item_output) = output.downcast_mut::<PutItemOutput>() {
let original = cfg.load::<OriginalRequest>().expect("we put this in ourselves");
let _original = original.0.downcast_ref::<PutItemInput>().expect("we know this type corresponds to the output type");

// Check the original type

let new = put_item_output.clone();

// Do the thing here

*put_item_output = new;
}
}
}

Ok(())
}
}

0 comments on commit 1bdab55

Please sign in to comment.