diff --git a/rustfmt.toml b/rustfmt.toml index 1181dd5..4f88472 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,6 +1,12 @@ -hard_tabs = true # use tab characters for indentation, spaces for alignment -use_field_init_shorthand = true -max_width = 120 use_small_heuristics = "Max" -chain_width = 80 fn_params_layout = "Compressed" +hard_tabs = true +use_field_init_shorthand = true +max_width = 100 +match_block_trailing_comma = true +# UNSTABLE: format_code_in_doc_comments = true +# UNSTABLE: overflow_delimited_expr = true +# UNSTABLE: comment_width = 100 +# UNSTABLE: format_macro_matchers = true +# UNSTABLE: format_strings = true +# UNSTABLE: group_imports = "StdExternalCrate" diff --git a/src/client.rs b/src/client.rs index 2428bb3..c6bf32e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -8,8 +8,8 @@ use std::sync::Arc; use crate::error::VssError; use crate::headers::{get_headermap, FixedHeaders, VssHeaderProvider}; use crate::types::{ - DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse, ListKeyVersionsRequest, - ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse, + DeleteObjectRequest, DeleteObjectResponse, GetObjectRequest, GetObjectResponse, + ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse, }; use crate::util::retry::{retry, RetryPolicy}; @@ -37,13 +37,20 @@ impl> VssClient { /// Constructs a [`VssClient`] from a given [`reqwest::Client`], using `base_url` as the VSS server endpoint. pub fn from_client(base_url: String, client: Client, retry_policy: R) -> Self { - Self { base_url, client, retry_policy, header_provider: Arc::new(FixedHeaders::new(HashMap::new())) } + Self { + base_url, + client, + retry_policy, + header_provider: Arc::new(FixedHeaders::new(HashMap::new())), + } } /// Constructs a [`VssClient`] using `base_url` as the VSS server endpoint. /// /// HTTP headers will be provided by the given `header_provider`. - pub fn new_with_headers(base_url: String, retry_policy: R, header_provider: Arc) -> Self { + pub fn new_with_headers( + base_url: String, retry_policy: R, header_provider: Arc, + ) -> Self { let client = Client::new(); Self { base_url, client, retry_policy, header_provider } } @@ -56,7 +63,9 @@ impl> VssClient { /// Fetches a value against a given `key` in `request`. /// Makes a service call to the `GetObject` endpoint of the VSS server. /// For API contract/usage, refer to docs for [`GetObjectRequest`] and [`GetObjectResponse`]. - pub async fn get_object(&self, request: &GetObjectRequest) -> Result { + pub async fn get_object( + &self, request: &GetObjectRequest, + ) -> Result { retry( || async { let url = format!("{}/getObject", self.base_url); @@ -79,7 +88,9 @@ impl> VssClient { /// Makes a service call to the `PutObject` endpoint of the VSS server, with multiple items. /// Items in the `request` are written in a single all-or-nothing transaction. /// For API contract/usage, refer to docs for [`PutObjectRequest`] and [`PutObjectResponse`]. - pub async fn put_object(&self, request: &PutObjectRequest) -> Result { + pub async fn put_object( + &self, request: &PutObjectRequest, + ) -> Result { retry( || async { let url = format!("{}/putObjects", self.base_url); @@ -93,7 +104,9 @@ impl> VssClient { /// Deletes the given `key` and `value` in `request`. /// Makes a service call to the `DeleteObject` endpoint of the VSS server. /// For API contract/usage, refer to docs for [`DeleteObjectRequest`] and [`DeleteObjectResponse`]. - pub async fn delete_object(&self, request: &DeleteObjectRequest) -> Result { + pub async fn delete_object( + &self, request: &DeleteObjectRequest, + ) -> Result { retry( || async { let url = format!("{}/deleteObject", self.base_url); @@ -120,7 +133,9 @@ impl> VssClient { .await } - async fn post_request(&self, request: &Rq, url: &str) -> Result { + async fn post_request( + &self, request: &Rq, url: &str, + ) -> Result { let request_body = request.encode_to_vec(); let headermap = self .header_provider diff --git a/src/crypto/chacha20.rs b/src/crypto/chacha20.rs index 3e3b874..6bc4971 100644 --- a/src/crypto/chacha20.rs +++ b/src/crypto/chacha20.rs @@ -166,7 +166,11 @@ mod real_chacha { ChaChaState { a: u32x4::from_bytes(&constant[0..16]), b: u32x4::from_bytes(&key[0..16]), - c: if key.len() == 16 { u32x4::from_bytes(&key[0..16]) } else { u32x4::from_bytes(&key[16..32]) }, + c: if key.len() == 16 { + u32x4::from_bytes(&key[0..16]) + } else { + u32x4::from_bytes(&key[16..32]) + }, d: if nonce.len() == 16 { u32x4::from_bytes(&nonce[0..16]) } else if nonce.len() == 12 { @@ -280,79 +284,92 @@ mod test { let test_vectors = vec![ TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], keystream: vec![ - 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, - 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, - 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, - 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, + 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, + 0x86, 0xbd, 0x28, 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, + 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, + 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, 0x6a, 0x43, 0xb8, 0xf4, + 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, ], }, TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], keystream: vec![ - 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96, - 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, 0x4f, 0x45, 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, - 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, 0xd2, 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, - 0x53, 0xd7, 0x92, 0xb1, 0xc4, 0x3f, 0xea, 0x81, 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, + 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, + 0x8e, 0x3c, 0x96, 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, 0x4f, 0x45, + 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, + 0xd2, 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, 0x53, 0xd7, 0x92, 0xb1, + 0xc4, 0x3f, 0xea, 0x81, 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, ], }, TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], keystream: vec![ - 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a, - 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, 0x4f, 0xcb, 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, - 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, 0x45, 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, - 0x52, 0x77, 0x06, 0x2e, 0xb7, 0xa0, 0x43, 0x3e, 0x44, 0x5f, 0x41, 0xe3, + 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, + 0x3f, 0x65, 0x3a, 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, 0x4f, 0xcb, + 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, + 0x45, 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, 0x52, 0x77, 0x06, 0x2e, + 0xb7, 0xa0, 0x43, 0x3e, 0x44, 0x5f, 0x41, 0xe3, ], }, TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], nonce: [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], keystream: vec![ - 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80, - 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, 0x33, 0x96, 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, - 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, 0x3c, 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, - 0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d, 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, + 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, + 0xd3, 0x3b, 0x80, 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, 0x33, 0x96, + 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, + 0x3c, 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, 0x5d, 0xdc, 0x49, 0x7a, + 0x0b, 0x46, 0x6e, 0x7d, 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, ], }, TestVector { key: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, ], nonce: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07], keystream: vec![ - 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, 0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75, - 0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93, 0xec, 0x01, 0xac, 0x56, 0xf8, 0x5a, 0xc3, 0xc1, - 0x34, 0xa4, 0x54, 0x7b, 0x73, 0x3b, 0x46, 0x41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0xdd, 0x5a, 0x97, 0xa5, 0xf5, 0x76, + 0xfe, 0x06, 0x40, 0x25, 0xd3, 0xce, 0x04, 0x2c, 0x56, 0x6a, 0xb2, 0xc5, 0x07, + 0xb1, 0x38, 0xdb, 0x85, 0x3e, 0x3d, 0x69, 0x59, 0x66, 0x09, 0x96, 0x54, 0x6c, + 0xc9, 0xc4, 0xa6, 0xea, 0xfd, 0xc7, 0x77, 0xc0, 0x40, 0xd7, 0x0e, 0xaf, 0x46, + 0xf7, 0x6d, 0xad, 0x39, 0x79, 0xe5, 0xc5, 0x36, 0x0c, 0x33, 0x17, 0x16, 0x6a, + 0x1c, 0x89, 0x4c, 0x94, 0xa3, 0x71, 0x87, 0x6a, 0x94, 0xdf, 0x76, 0x28, 0xfe, + 0x4e, 0xaa, 0xf2, 0xcc, 0xb2, 0x7d, 0x5a, 0xaa, 0xe0, 0xad, 0x7a, 0xd0, 0xf9, + 0xd4, 0xb6, 0xad, 0x3b, 0x54, 0x09, 0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, + 0x7a, 0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9, ], }, ]; @@ -377,79 +394,92 @@ mod test { let test_vectors = vec![ TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], keystream: vec![ - 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, - 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, - 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, - 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, + 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, + 0x86, 0xbd, 0x28, 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, + 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, + 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, 0x6a, 0x43, 0xb8, 0xf4, + 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, ], }, TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], keystream: vec![ - 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96, - 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, 0x4f, 0x45, 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, - 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, 0xd2, 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, - 0x53, 0xd7, 0x92, 0xb1, 0xc4, 0x3f, 0xea, 0x81, 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, + 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, + 0x8e, 0x3c, 0x96, 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, 0x4f, 0x45, + 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, + 0xd2, 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, 0x53, 0xd7, 0x92, 0xb1, + 0xc4, 0x3f, 0xea, 0x81, 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, ], }, TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], keystream: vec![ - 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a, - 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, 0x4f, 0xcb, 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, - 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, 0x45, 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, - 0x52, 0x77, 0x06, 0x2e, 0xb7, 0xa0, 0x43, 0x3e, 0x44, 0x5f, 0x41, 0xe3, + 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, + 0x3f, 0x65, 0x3a, 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, 0x4f, 0xcb, + 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, + 0x45, 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, 0x52, 0x77, 0x06, 0x2e, + 0xb7, 0xa0, 0x43, 0x3e, 0x44, 0x5f, 0x41, 0xe3, ], }, TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], keystream: vec![ - 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80, - 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, 0x33, 0x96, 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, - 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, 0x3c, 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, - 0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d, 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, + 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, + 0xd3, 0x3b, 0x80, 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, 0x33, 0x96, + 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, + 0x3c, 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, 0x5d, 0xdc, 0x49, 0x7a, + 0x0b, 0x46, 0x6e, 0x7d, 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, ], }, TestVector { key: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, ], nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07], keystream: vec![ - 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, 0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75, - 0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93, 0xec, 0x01, 0xac, 0x56, 0xf8, 0x5a, 0xc3, 0xc1, - 0x34, 0xa4, 0x54, 0x7b, 0x73, 0x3b, 0x46, 0x41, 0x30, 0x42, 0xc9, 0x44, 0x00, 0x49, 0x17, 0x69, - 0x05, 0xd3, 0xbe, 0x59, 0xea, 0x1c, 0x53, 0xf1, 0x59, 0x16, 0x15, 0x5c, 0x2b, 0xe8, 0x24, 0x1a, - 0x38, 0x00, 0x8b, 0x9a, 0x26, 0xbc, 0x35, 0x94, 0x1e, 0x24, 0x44, 0x17, 0x7c, 0x8a, 0xde, 0x66, - 0x89, 0xde, 0x95, 0x26, 0x49, 0x86, 0xd9, 0x58, 0x89, 0xfb, 0x60, 0xe8, 0x46, 0x29, 0xc9, 0xbd, - 0x9a, 0x5a, 0xcb, 0x1c, 0xc1, 0x18, 0xbe, 0x56, 0x3e, 0xb9, 0xb3, 0xa4, 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 0x54, 0x7b, 0x73, 0x3b, 0x46, + 0x41, 0x30, 0x42, 0xc9, 0x44, 0x00, 0x49, 0x17, 0x69, 0x05, 0xd3, 0xbe, 0x59, + 0xea, 0x1c, 0x53, 0xf1, 0x59, 0x16, 0x15, 0x5c, 0x2b, 0xe8, 0x24, 0x1a, 0x38, + 0x00, 0x8b, 0x9a, 0x26, 0xbc, 0x35, 0x94, 0x1e, 0x24, 0x44, 0x17, 0x7c, 0x8a, + 0xde, 0x66, 0x89, 0xde, 0x95, 0x26, 0x49, 0x86, 0xd9, 0x58, 0x89, 0xfb, 0x60, + 0xe8, 0x46, 0x29, 0xc9, 0xbd, 0x9a, 0x5a, 0xcb, 0x1c, 0xc1, 0x18, 0xbe, 0x56, + 0x3e, 0xb9, 0xb3, 0xa4, 0xa4, 0x72, 0xf8, 0x2e, 0x09, 0xa7, 0xe7, 0x78, 0x49, + 0x2b, 0x56, 0x2e, 0xf7, 0x13, 0x0e, 0x88, 0xdf, 0xe0, 0x31, 0xc7, 0x9d, 0xb9, + 0xd4, 0xf7, 0xc7, 0xa8, 0x99, 0x15, 0x1b, 0x9a, 0x47, 0x50, 0x32, 0xb6, 0x3f, + 0xc3, 0x85, 0x24, 0x5f, 0xe0, 0x54, 0xe3, 0xdd, 0x5a, 0x97, 0xa5, 0xf5, 0x76, + 0xfe, 0x06, 0x40, 0x25, 0xd3, 0xce, 0x04, 0x2c, 0x56, 0x6a, 0xb2, 0xc5, 0x07, + 0xb1, 0x38, 0xdb, 0x85, 0x3e, 0x3d, 0x69, 0x59, 0x66, 0x09, 0x96, 0x54, 0x6c, + 0xc9, 0xc4, 0xa6, 0xea, 0xfd, 0xc7, 0x77, 0xc0, 0x40, 0xd7, 0x0e, 0xaf, 0x46, + 0xf7, 0x6d, 0xad, 0x39, 0x79, 0xe5, 0xc5, 0x36, 0x0c, 0x33, 0x17, 0x16, 0x6a, + 0x1c, 0x89, 0x4c, 0x94, 0xa3, 0x71, 0x87, 0x6a, 0x94, 0xdf, 0x76, 0x28, 0xfe, + 0x4e, 0xaa, 0xf2, 0xcc, 0xb2, 0x7d, 0x5a, 0xaa, 0xe0, 0xad, 0x7a, 0xd0, 0xf9, + 0xd4, 0xb6, 0xad, 0x3b, 0x54, 0x09, 0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, + 0x7a, 0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9, ], }, ]; diff --git a/src/crypto/chacha20poly1305.rs b/src/crypto/chacha20poly1305.rs index 8b6be00..9efe49f 100644 --- a/src/crypto/chacha20poly1305.rs +++ b/src/crypto/chacha20poly1305.rs @@ -48,7 +48,13 @@ mod real_chachapoly { mac.input(aad); ChaCha20Poly1305::pad_mac_16(&mut mac, aad.len()); - ChaCha20Poly1305 { cipher, mac, finished: false, data_len: 0, aad_len: aad.len() as u64 } + ChaCha20Poly1305 { + cipher, + mac, + finished: false, + data_len: 0, + aad_len: aad.len() as u64, + } } pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) { diff --git a/src/crypto/poly1305.rs b/src/crypto/poly1305.rs index 384a724..3a56d20 100644 --- a/src/crypto/poly1305.rs +++ b/src/crypto/poly1305.rs @@ -24,15 +24,22 @@ pub struct Poly1305 { impl Poly1305 { pub fn new(key: &[u8]) -> Poly1305 { assert!(key.len() == 32); - let mut poly = - Poly1305 { r: [0u32; 5], h: [0u32; 5], pad: [0u32; 4], leftover: 0, buffer: [0u8; 16], finalized: false }; + let mut poly = Poly1305 { + r: [0u32; 5], + h: [0u32; 5], + pad: [0u32; 4], + leftover: 0, + buffer: [0u8; 16], + finalized: false, + }; // r &= 0xffffffc0ffffffc0ffffffc0fffffff poly.r[0] = (u32::from_le_bytes(key[0..4].try_into().expect("len is 4"))) & 0x3ffffff; poly.r[1] = (u32::from_le_bytes(key[3..7].try_into().expect("len is 4")) >> 2) & 0x3ffff03; poly.r[2] = (u32::from_le_bytes(key[6..10].try_into().expect("len is 4")) >> 4) & 0x3ffc0ff; poly.r[3] = (u32::from_le_bytes(key[9..13].try_into().expect("len is 4")) >> 6) & 0x3f03fff; - poly.r[4] = (u32::from_le_bytes(key[12..16].try_into().expect("len is 4")) >> 8) & 0x00fffff; + poly.r[4] = + (u32::from_le_bytes(key[12..16].try_into().expect("len is 4")) >> 8) & 0x00fffff; poly.pad[0] = u32::from_le_bytes(key[16..20].try_into().expect("len is 4")); poly.pad[1] = u32::from_le_bytes(key[20..24].try_into().expect("len is 4")); @@ -272,22 +279,28 @@ mod test { #[test] fn test_nacl_vector() { let key = [ - 0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, 0x6d, 0x11, 0xc2, 0xcb, 0x21, 0x4d, 0x3c, 0x25, 0x25, 0x39, - 0x12, 0x1d, 0x8e, 0x23, 0x4e, 0x65, 0x2d, 0x65, 0x1f, 0xa4, 0xc8, 0xcf, 0xf8, 0x80, + 0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, 0x6d, 0x11, 0xc2, 0xcb, 0x21, 0x4d, + 0x3c, 0x25, 0x25, 0x39, 0x12, 0x1d, 0x8e, 0x23, 0x4e, 0x65, 0x2d, 0x65, 0x1f, 0xa4, + 0xc8, 0xcf, 0xf8, 0x80, ]; let msg = [ - 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce, 0x48, 0x33, - 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, 0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a, 0xc0, 0xdf, 0xc1, 0x7c, - 0x98, 0xdc, 0xe8, 0x7b, 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, - 0x8f, 0xe2, 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38,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b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74, 0xe3, 0x55, 0xa5, ]; - let expected = [0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9]; + let expected = [ + 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, + 0x05, 0xd9, + ]; let mut mac = [0u8; 16]; poly1305(&key, &msg, &mut mac); @@ -312,25 +325,35 @@ mod test { #[test] fn donna_self_test() { let wrap_key = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, ]; - let wrap_msg = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]; + let wrap_msg = [ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, + ]; - let wrap_mac = [0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + let wrap_mac = [ + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + ]; let mut mac = [0u8; 16]; poly1305(&wrap_key, &wrap_msg, &mut mac); assert_eq!(&mac[..], &wrap_mac[..]); let total_key = [ - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, ]; - let total_mac = - [0x64, 0xaf, 0xe2, 0xe8, 0xd6, 0xad, 0x7b, 0xbd, 0xd2, 0x87, 0xf9, 0x7c, 0x44, 0x62, 0x3d, 0x39]; + let total_mac = [ + 0x64, 0xaf, 0xe2, 0xe8, 0xd6, 0xad, 0x7b, 0xbd, 0xd2, 0x87, 0xf9, 0x7c, 0x44, 0x62, + 0x3d, 0x39, + ]; let mut tpoly = Poly1305::new(&total_key); for i in 0..256 { @@ -349,13 +372,19 @@ mod test { // from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04 let key = b"this is 32-byte key for Poly1305"; let msg = [0u8; 32]; - let expected = [0x49, 0xec, 0x78, 0x09, 0x0e, 0x48, 0x1e, 0xc6, 0xc2, 0x6b, 0x33, 0xb9, 0x1c, 0xcc, 0x03, 0x07]; + let expected = [ + 0x49, 0xec, 0x78, 0x09, 0x0e, 0x48, 0x1e, 0xc6, 0xc2, 0x6b, 0x33, 0xb9, 0x1c, 0xcc, + 0x03, 0x07, + ]; let mut mac = [0u8; 16]; poly1305(key, &msg, &mut mac); assert_eq!(&mac[..], &expected[..]); let msg = b"Hello world!"; - let expected = [0xa6, 0xf7, 0x45, 0x00, 0x8f, 0x81, 0xc9, 0x16, 0xa2, 0x0d, 0xcc, 0x74, 0xee, 0xf2, 0xb2, 0xf0]; + let expected = [ + 0xa6, 0xf7, 0x45, 0x00, 0x8f, 0x81, 0xc9, 0x16, 0xa2, 0x0d, 0xcc, 0x74, 0xee, 0xf2, + 0xb2, 0xf0, + ]; poly1305(key, msg, &mut mac); assert_eq!(&mac[..], &expected[..]); } diff --git a/src/error.rs b/src/error.rs index 63065c0..5955e6a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -36,10 +36,12 @@ impl VssError { match ErrorResponse::decode(&payload[..]) { Ok(error_response) => VssError::from(error_response), Err(e) => { - let message = - format!("Unable to decode ErrorResponse from server, HttpStatusCode: {}, DecodeErr: {}", status, e); + let message = format!( + "Unable to decode ErrorResponse from server, HttpStatusCode: {}, DecodeErr: {}", + status, e + ); VssError::InternalError(message) - } + }, } } } @@ -49,22 +51,22 @@ impl Display for VssError { match self { VssError::NoSuchKeyError(message) => { write!(f, "Requested key does not exist: {}", message) - } + }, VssError::InvalidRequestError(message) => { write!(f, "Request sent to VSS Storage was invalid: {}", message) - } + }, VssError::ConflictError(message) => { write!(f, "Potential version conflict in write operation: {}", message) - } + }, VssError::AuthError(message) => { write!(f, "Authentication or Authorization failure: {}", message) - } + }, VssError::InternalServerError(message) => { write!(f, "InternalServerError: {}", message) - } + }, VssError::InternalError(message) => { write!(f, "InternalError: {}", message) - } + }, } } } @@ -75,10 +77,14 @@ impl From for VssError { fn from(error_response: ErrorResponse) -> Self { match error_response.error_code() { ErrorCode::NoSuchKeyException => VssError::NoSuchKeyError(error_response.message), - ErrorCode::InvalidRequestException => VssError::InvalidRequestError(error_response.message), + ErrorCode::InvalidRequestException => { + VssError::InvalidRequestError(error_response.message) + }, ErrorCode::ConflictException => VssError::ConflictError(error_response.message), ErrorCode::AuthException => VssError::AuthError(error_response.message), - ErrorCode::InternalServerException => VssError::InternalServerError(error_response.message), + ErrorCode::InternalServerException => { + VssError::InternalServerError(error_response.message) + }, _ => VssError::InternalError(format!( "VSS responded with an unknown error code: {}, message: {}", error_response.error_code, error_response.message diff --git a/src/headers/lnurl_auth_jwt.rs b/src/headers/lnurl_auth_jwt.rs index ca0415b..2d13fe2 100644 --- a/src/headers/lnurl_auth_jwt.rs +++ b/src/headers/lnurl_auth_jwt.rs @@ -72,9 +72,10 @@ impl LnurlAuthToJwtProvider { seed: &[u8], url: String, default_headers: HashMap, ) -> Result { let engine = Secp256k1::signing_only(); - let master = Xpriv::new_master(Network::Testnet, seed).map_err(VssHeaderProviderError::from)?; - let child_number = - ChildNumber::from_hardened_idx(PARENT_DERIVATION_INDEX).map_err(VssHeaderProviderError::from)?; + let master = + Xpriv::new_master(Network::Testnet, seed).map_err(VssHeaderProviderError::from)?; + let child_number = ChildNumber::from_hardened_idx(PARENT_DERIVATION_INDEX) + .map_err(VssHeaderProviderError::from)?; let parent_key = master .derive_priv(&engine, &vec![child_number]) .map_err(VssHeaderProviderError::from)?; @@ -124,12 +125,12 @@ impl LnurlAuthToJwtProvider { return Err(VssHeaderProviderError::AuthorizationError { error: format!("LNURL Auth failed, reason is: {}", reason.escape_debug()), }); - } + }, _ => { return Err(VssHeaderProviderError::InvalidData { error: "LNURL Auth response did not contain a token nor an error".to_string(), }); - } + }, }; parse_jwt_token(untrusted_token) } @@ -153,7 +154,9 @@ impl LnurlAuthToJwtProvider { #[async_trait] impl VssHeaderProvider for LnurlAuthToJwtProvider { - async fn get_headers(&self, _request: &[u8]) -> Result, VssHeaderProviderError> { + async fn get_headers( + &self, _request: &[u8], + ) -> Result, VssHeaderProviderError> { let jwt_token = self.get_jwt_token(false).await?; let mut headers = self.default_headers.clone(); headers.insert(AUTHORIZATION.to_string(), format!("Bearer {}", jwt_token)); @@ -161,16 +164,20 @@ impl VssHeaderProvider for LnurlAuthToJwtProvider { } } -fn hashing_key(engine: &Secp256k1, parent_key: &Xpriv) -> Result { - let hashing_child_number = - ChildNumber::from_normal_idx(HASHING_DERIVATION_INDEX).map_err(VssHeaderProviderError::from)?; +fn hashing_key( + engine: &Secp256k1, parent_key: &Xpriv, +) -> Result { + let hashing_child_number = ChildNumber::from_normal_idx(HASHING_DERIVATION_INDEX) + .map_err(VssHeaderProviderError::from)?; parent_key .derive_priv(engine, &vec![hashing_child_number]) .map(|xpriv| xpriv.to_priv()) .map_err(VssHeaderProviderError::from) } -fn linking_key_path(hashing_key: &PrivateKey, domain_name: &str) -> Result { +fn linking_key_path( + hashing_key: &PrivateKey, domain_name: &str, +) -> Result { let mut engine = HmacEngine::::new(&hashing_key.inner[..]); engine.input(domain_name.as_bytes()); let result = Hmac::::from_engine(engine).to_byte_array(); @@ -187,8 +194,9 @@ fn sign_lnurl( engine: &Secp256k1, parent_key: &Xpriv, lnurl_str: &str, ) -> Result { // Parse k1 parameter to sign. - let invalid_lnurl = - || VssHeaderProviderError::InvalidData { error: format!("invalid lnurl: {}", lnurl_str.escape_debug()) }; + let invalid_lnurl = || VssHeaderProviderError::InvalidData { + error: format!("invalid lnurl: {}", lnurl_str.escape_debug()), + }; let mut lnurl = Url::parse(lnurl_str).map_err(|_| invalid_lnurl())?; let domain = lnurl.domain().ok_or(invalid_lnurl())?; let k1_str = lnurl @@ -207,8 +215,9 @@ fn sign_lnurl( .map_err(VssHeaderProviderError::from)? .to_priv(); let linking_public_key = linking_private_key.public_key(engine); - let message = Message::from_digest_slice(&k1) - .map_err(|_| VssHeaderProviderError::InvalidData { error: format!("invalid k1: {:?}", k1) })?; + let message = Message::from_digest_slice(&k1).map_err(|_| { + VssHeaderProviderError::InvalidData { error: format!("invalid k1: {:?}", k1) } + })?; let sig = engine.sign_ecdsa(&message, &linking_private_key.inner); // Compose LNURL with signature and linking public key. @@ -233,8 +242,9 @@ struct ExpiryClaim { fn parse_jwt_token(jwt_token: String) -> Result { let parts: Vec<&str> = jwt_token.split('.').collect(); - let invalid = - || VssHeaderProviderError::InvalidData { error: format!("invalid JWT token: {}", jwt_token.escape_debug()) }; + let invalid = || VssHeaderProviderError::InvalidData { + error: format!("invalid JWT token: {}", jwt_token.escape_debug()), + }; if parts.len() != 3 { return Err(invalid()); } @@ -242,9 +252,8 @@ fn parse_jwt_token(jwt_token: String) -> Result Result, VssHeaderProviderError>; + async fn get_headers( + &self, request: &[u8], + ) -> Result, VssHeaderProviderError>; } /// Errors around providing headers for each VSS request. @@ -53,16 +55,16 @@ impl Display for VssHeaderProviderError { match self { Self::InvalidData { error } => { write!(f, "invalid data: {}", error) - } + }, Self::RequestError { error } => { write!(f, "error performing external request: {}", error) - } + }, Self::AuthorizationError { error } => { write!(f, "authorization was refused: {}", error) - } + }, Self::InternalError { error } => { write!(f, "internal error: {}", error) - } + }, } } } @@ -83,12 +85,16 @@ impl FixedHeaders { #[async_trait] impl VssHeaderProvider for FixedHeaders { - async fn get_headers(&self, _request: &[u8]) -> Result, VssHeaderProviderError> { + async fn get_headers( + &self, _request: &[u8], + ) -> Result, VssHeaderProviderError> { Ok(self.headers.clone()) } } -pub(crate) fn get_headermap(headers: &HashMap) -> Result { +pub(crate) fn get_headermap( + headers: &HashMap, +) -> Result { let mut headermap = HeaderMap::new(); for (name, value) in headers { headermap.insert( diff --git a/src/util/retry.rs b/src/util/retry.rs index 0ee9cb3..a39498d 100644 --- a/src/util/retry.rs +++ b/src/util/retry.rs @@ -64,15 +64,17 @@ where Ok(result) => return Ok(result), Err(err) => { attempts_made += 1; - if let Some(delay) = - retry_policy.next_delay(&RetryContext { attempts_made, accumulated_delay, error: &err }) - { + if let Some(delay) = retry_policy.next_delay(&RetryContext { + attempts_made, + accumulated_delay, + error: &err, + }) { tokio::time::sleep(delay).await; accumulated_delay += delay; } else { return Err(err); } - } + }, } } } @@ -211,7 +213,8 @@ impl RetryPolicy for JitteredRetryPolicy { fn next_delay(&self, context: &RetryContext) -> Option { if let Some(base_delay) = self.inner_policy.next_delay(context) { let mut rng = rand::thread_rng(); - let jitter = Duration::from_micros(rng.gen_range(0..self.max_jitter.as_micros() as u64)); + let jitter = + Duration::from_micros(rng.gen_range(0..self.max_jitter.as_micros() as u64)); Some(base_delay + jitter) } else { None diff --git a/src/util/storable_builder.rs b/src/util/storable_builder.rs index 990f46b..02df8b0 100644 --- a/src/util/storable_builder.rs +++ b/src/util/storable_builder.rs @@ -64,11 +64,12 @@ impl StorableBuilder { /// [`PutObjectRequest`]: crate::types::PutObjectRequest pub fn deconstruct(&self, mut storable: Storable) -> io::Result<(Vec, i64)> { let encryption_metadata = storable.encryption_metadata.unwrap(); - let mut cipher = ChaCha20Poly1305::new(&self.data_encryption_key, &encryption_metadata.nonce, &[]); + let mut cipher = + ChaCha20Poly1305::new(&self.data_encryption_key, &encryption_metadata.nonce, &[]); if cipher.decrypt_inplace(&mut storable.data, encryption_metadata.tag.borrow()) { - let data_blob = - PlaintextBlob::decode(&storable.data[..]).map_err(|e| Error::new(ErrorKind::InvalidData, e))?; + let data_blob = PlaintextBlob::decode(&storable.data[..]) + .map_err(|e| Error::new(ErrorKind::InvalidData, e))?; Ok((data_blob.value, data_blob.version)) } else { Err(Error::new(ErrorKind::InvalidData, "Invalid Tag")) @@ -96,7 +97,10 @@ mod tests { let test_entropy_provider = TestEntropyProvider; let mut data_key = [0u8; 32]; test_entropy_provider.fill_bytes(&mut data_key); - let storable_builder = StorableBuilder { data_encryption_key: data_key, entropy_source: test_entropy_provider }; + let storable_builder = StorableBuilder { + data_encryption_key: data_key, + entropy_source: test_entropy_provider, + }; let expected_data = b"secret".to_vec(); let expected_version = 8; let storable = storable_builder.build(expected_data.clone(), expected_version); diff --git a/tests/lnurl_auth_jwt_tests.rs b/tests/lnurl_auth_jwt_tests.rs index e90c6e6..c2b651c 100644 --- a/tests/lnurl_auth_jwt_tests.rs +++ b/tests/lnurl_auth_jwt_tests.rs @@ -34,7 +34,8 @@ mod lnurl_auth_jwt_tests { // Initialize LNURL Auth JWT provider connecting to the mock server. let addr = mockito::server_address(); let base_url = format!("http://localhost:{}", addr.port()); - let lnurl_auth_jwt = LnurlAuthToJwtProvider::new(&[0; 32], base_url.clone(), HashMap::new()).unwrap(); + let lnurl_auth_jwt = + LnurlAuthToJwtProvider::new(&[0; 32], base_url.clone(), HashMap::new()).unwrap(); { // First request will be provided with an expired JWT token. let k1 = "0000000000000000000000000000000000000000000000000000000000000000"; @@ -67,7 +68,8 @@ mod lnurl_auth_jwt_tests { // This will be cached. let k1 = "1000000000000000000000000000000000000000000000000000000000000000"; let valid_jwt = jwt_with_expiry( - SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() + 60 * 60 * 24 * 365, + SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() + + 60 * 60 * 24 * 365, ); let lnurl = mockito::mock("GET", "/") .expect(1) diff --git a/tests/retry_tests.rs b/tests/retry_tests.rs index 1ce664d..dc7c20d 100644 --- a/tests/retry_tests.rs +++ b/tests/retry_tests.rs @@ -57,7 +57,8 @@ mod retry_tests { #[tokio::test] async fn test_retry_on_all_errors() { - let retry_policy = ExponentialBackoffRetryPolicy::new(Duration::from_millis(10)).with_max_attempts(3); + let retry_policy = + ExponentialBackoffRetryPolicy::new(Duration::from_millis(10)).with_max_attempts(3); let call_count = Arc::new(AtomicU32::new(0)); let count = call_count.clone(); diff --git a/tests/tests.rs b/tests/tests.rs index eb9a5cf..4a38c7c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -14,8 +14,9 @@ mod tests { use vss_client::headers::VssHeaderProviderError; use vss_client::types::{ - DeleteObjectRequest, DeleteObjectResponse, ErrorCode, ErrorResponse, GetObjectRequest, GetObjectResponse, - KeyValue, ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest, PutObjectResponse, + DeleteObjectRequest, DeleteObjectResponse, ErrorCode, ErrorResponse, GetObjectRequest, + GetObjectResponse, KeyValue, ListKeyVersionsRequest, ListKeyVersionsResponse, + PutObjectRequest, PutObjectResponse, }; use vss_client::util::retry::{ExponentialBackoffRetryPolicy, RetryPolicy}; @@ -80,8 +81,10 @@ mod tests { .create(); // Create a new VssClient with the mock server URL and fixed headers. - let header_provider = - Arc::new(FixedHeaders::new(HashMap::from([("headerkey".to_string(), "headervalue".to_string())]))); + let header_provider = Arc::new(FixedHeaders::new(HashMap::from([( + "headerkey".to_string(), + "headervalue".to_string(), + )]))); let client = VssClient::new_with_headers(base_url, retry_policy(), header_provider); let actual_result = client.get_object(&get_request).await.unwrap(); @@ -102,7 +105,11 @@ mod tests { let request = PutObjectRequest { store_id: "store".to_string(), global_version: Some(4), - transaction_items: vec![KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }], + transaction_items: vec![KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }], delete_items: vec![], }; let mock_response = PutObjectResponse::default(); @@ -134,7 +141,11 @@ mod tests { // Set up the mock request/response. let request = DeleteObjectRequest { store_id: "store".to_string(), - key_value: Some(KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }), + key_value: Some(KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }), }; let mock_response = DeleteObjectResponse::default(); @@ -215,7 +226,10 @@ mod tests { .create(); let get_result = vss_client - .get_object(&GetObjectRequest { store_id: "store".to_string(), key: "non_existent_key".to_string() }) + .get_object(&GetObjectRequest { + store_id: "store".to_string(), + key: "non_existent_key".to_string(), + }) .await; assert!(matches!(get_result.unwrap_err(), VssError::NoSuchKeyError { .. })); @@ -268,7 +282,11 @@ mod tests { .put_object(&PutObjectRequest { store_id: "store".to_string(), global_version: Some(4), - transaction_items: vec![KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }], + transaction_items: vec![KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }], delete_items: vec![], }) .await; @@ -277,7 +295,11 @@ mod tests { let delete_result = vss_client .delete_object(&DeleteObjectRequest { store_id: "store".to_string(), - key_value: Some(KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }), + key_value: Some(KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }), }) .await; assert!(matches!(delete_result.unwrap_err(), VssError::InvalidRequestError { .. })); @@ -302,8 +324,10 @@ mod tests { let vss_client = VssClient::new(base_url, retry_policy()); // Invalid Request Error - let error_response = - ErrorResponse { error_code: ErrorCode::AuthException.into(), message: "AuthException".to_string() }; + let error_response = ErrorResponse { + error_code: ErrorCode::AuthException.into(), + message: "AuthException".to_string(), + }; let mock_server = mockito::mock("POST", Matcher::Any) .with_status(401) .with_body(&error_response.encode_to_vec()) @@ -318,7 +342,11 @@ mod tests { .put_object(&PutObjectRequest { store_id: "store".to_string(), global_version: Some(4), - transaction_items: vec![KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }], + transaction_items: vec![KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }], delete_items: vec![], }) .await; @@ -327,7 +355,11 @@ mod tests { let delete_result = vss_client .delete_object(&DeleteObjectRequest { store_id: "store".to_string(), - key_value: Some(KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }), + key_value: Some(KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }), }) .await; assert!(matches!(delete_result.unwrap_err(), VssError::AuthError { .. })); @@ -350,7 +382,9 @@ mod tests { #[async_trait] impl VssHeaderProvider for FailingHeaderProvider { - async fn get_headers(&self, _request: &[u8]) -> Result, VssHeaderProviderError> { + async fn get_headers( + &self, _request: &[u8], + ) -> Result, VssHeaderProviderError> { Err(VssHeaderProviderError::InvalidData { error: "test".to_string() }) } } @@ -359,7 +393,8 @@ mod tests { async fn test_header_provider_error() { let get_request = GetObjectRequest { store_id: "store".to_string(), key: "k1".to_string() }; let header_provider = Arc::new(FailingHeaderProvider {}); - let client = VssClient::new_with_headers("notused".to_string(), retry_policy(), header_provider); + let client = + VssClient::new_with_headers("notused".to_string(), retry_policy(), header_provider); let result = client.get_object(&get_request).await; assert!(matches!(result, Err(VssError::AuthError { .. }))); @@ -371,8 +406,10 @@ mod tests { let vss_client = VssClient::new(base_url, retry_policy()); // Conflict Error - let error_response = - ErrorResponse { error_code: ErrorCode::ConflictException.into(), message: "ConflictException".to_string() }; + let error_response = ErrorResponse { + error_code: ErrorCode::ConflictException.into(), + message: "ConflictException".to_string(), + }; let mock_server = mockito::mock("POST", Matcher::Any) .with_status(409) .with_body(&error_response.encode_to_vec()) @@ -382,7 +419,11 @@ mod tests { .put_object(&PutObjectRequest { store_id: "store".to_string(), global_version: Some(4), - transaction_items: vec![KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }], + transaction_items: vec![KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }], delete_items: vec![], }) .await; @@ -416,7 +457,11 @@ mod tests { .put_object(&PutObjectRequest { store_id: "store".to_string(), global_version: Some(4), - transaction_items: vec![KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }], + transaction_items: vec![KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }], delete_items: vec![], }) .await; @@ -425,7 +470,11 @@ mod tests { let delete_result = vss_client .delete_object(&DeleteObjectRequest { store_id: "store".to_string(), - key_value: Some(KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }), + key_value: Some(KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }), }) .await; assert!(matches!(delete_result.unwrap_err(), VssError::InternalServerError { .. })); @@ -449,7 +498,8 @@ mod tests { let base_url = mockito::server_url(); let vss_client = VssClient::new(base_url, retry_policy()); - let error_response = ErrorResponse { error_code: 999, message: "UnknownException".to_string() }; + let error_response = + ErrorResponse { error_code: 999, message: "UnknownException".to_string() }; let mut _mock_server = mockito::mock("POST", Matcher::Any) .with_status(999) .with_body(&error_response.encode_to_vec()) @@ -462,7 +512,11 @@ mod tests { let put_request = PutObjectRequest { store_id: "store".to_string(), global_version: Some(4), - transaction_items: vec![KeyValue { key: "k1".to_string(), version: 2, value: b"k1v3".to_vec() }], + transaction_items: vec![KeyValue { + key: "k1".to_string(), + version: 2, + value: b"k1v3".to_vec(), + }], delete_items: vec![], }; let put_result = vss_client.put_object(&put_request).await;