Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrenz committed Nov 12, 2024
1 parent f3509a4 commit a7ec1a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/snowflake/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::{collections::HashMap, sync::Arc, time::{Duration, Instant, SystemTime,
use tokio::sync::Mutex;
use zeroize::Zeroize;
use moka::future::Cache;
use crate::{duration_on_drop, error::{Error, RetryState, Kind as ErrorKind}, metrics};
use crate::{duration_on_drop, error::{Error, RetryState}, metrics};
use crate::util::{deserialize_str, deserialize_slice};
use crate::encryption::Key;
use super::resolver::HickoryResolverWithEdns;


Expand Down
14 changes: 7 additions & 7 deletions src/snowflake/kms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl CryptoMaterialProvider for SnowflakeStageS3Kms {
let path = path.strip_prefix(&self.prefix).unwrap_or(path);

let material_description: MaterialDescription =
deserialize_str(required_attribute("x-amz-matdesc", &attr)?)
deserialize_str(required_attribute(&attr, "x-amz-matdesc")?)
.map_err(Error::deserialize_response_err("failed to deserialize matdesc"))?;

let master_key = get_master_key(
Expand All @@ -150,13 +150,13 @@ impl CryptoMaterialProvider for SnowflakeStageS3Kms {
&self.keyring,
).await?;

let cek = EncryptedKey::from_base64(required_attribute("x-amz-key", &attr)?)
let cek = EncryptedKey::from_base64(required_attribute(&attr, "x-amz-key")?)
.map_err(ErrorKind::MaterialDecode)?;
let cek = cek.decrypt_aes_128_ecb(&master_key)
.map_err(ErrorKind::MaterialCrypt)?;
let iv = Iv::from_base64(required_attribute("x-amz-iv", &attr)?)
let iv = Iv::from_base64(required_attribute(&attr, "x-amz-iv")?)
.map_err(ErrorKind::MaterialDecode)?;
let alg = required_attribute("x-amz-cek-alg", &attr);
let alg = required_attribute(&attr, "x-amz-cek-alg");

let scheme = match alg {
Ok("AES/GCM/NoPadding") => CryptoScheme::Aes256Gcm,
Expand Down Expand Up @@ -225,7 +225,7 @@ const AZURE_ENCDATA_KEY: &str = "encryptiondata";

#[async_trait::async_trait]
impl CryptoMaterialProvider for SnowflakeStageAzureKms {
async fn material_for_write(&self, _path: &str, data_len: Option<usize>) -> crate::Result<(ContentCryptoMaterial, Attributes)> {
async fn material_for_write(&self, _path: &str, _data_len: Option<usize>) -> crate::Result<(ContentCryptoMaterial, Attributes)> {
let _guard = duration_on_drop!(metrics::material_for_write_duration);
let info = self.client.current_upload_info(&self.stage).await?;

Expand Down Expand Up @@ -292,7 +292,7 @@ impl CryptoMaterialProvider for SnowflakeStageAzureKms {
let path = path.strip_prefix(&self.prefix).unwrap_or(path);

let material_description: MaterialDescription =
deserialize_str(required_attribute(AZURE_MATDESC_KEY, &attr)?)
deserialize_str(required_attribute(&attr, AZURE_MATDESC_KEY)?)
.map_err(Error::deserialize_response_err("failed to deserialize matdesc"))?;

let master_key = get_master_key(
Expand All @@ -304,7 +304,7 @@ impl CryptoMaterialProvider for SnowflakeStageAzureKms {
).await?;

let encryption_data: EncryptionData =
deserialize_str(required_attribute(AZURE_ENCDATA_KEY, &attr)?)
deserialize_str(required_attribute(&attr, AZURE_ENCDATA_KEY)?)
.map_err(Error::deserialize_response_err("failed to deserialize encryption data"))?;

let cek = EncryptedKey::from_base64(&encryption_data.wrapped_content_key.encrypted_key)
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ where
serde_path_to_error::deserialize(de)
}

pub(crate) fn required_attribute<'a>(key: &'static str, attr: &'a Attributes) -> Result<&'a str, Error> {
pub(crate) fn required_attribute<'a>(attr: &'a Attributes, key: &'static str) -> Result<&'a str, Error> {
let v: &str = attr.get(&Attribute::Metadata(key.into()))
.ok_or_else(|| Error::required_config(format!("missing required attribute `{}`", key)))?
.as_ref();
Expand Down

0 comments on commit a7ec1a7

Please sign in to comment.