mirror of
https://github.com/narrrl/proton-sdk-rs.git
synced 2026-11-03 16:41:26 +01:00
cargo fmt + clippy
This commit is contained in:
1 parent
70e573ebe1
commit
c98ec2d55d
12 files changed
+76
-67
No files matched your search
@@ -4,8 +4,8 @@ use std::collections::HashMap;
|
|||||||
use std::io::{Cursor, Read};
|
use std::io::{Cursor, Read};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
@@ -13,8 +13,8 @@ use proton_sdk::account::AccountClient;
|
|||||||
use proton_sdk::cache::{CacheRepository, InMemoryCacheRepository};
|
use proton_sdk::cache::{CacheRepository, InMemoryCacheRepository};
|
||||||
use proton_sdk::crypto::PrivateKey;
|
use proton_sdk::crypto::PrivateKey;
|
||||||
use proton_sdk::crypto::{
|
use proton_sdk::crypto::{
|
||||||
build_volume_creation_material, generate_node_hash_key, generate_node_key,
|
ContentKey, VerificationKeyRing, VerificationStatus, build_volume_creation_material,
|
||||||
generate_node_key_aead, verify_detached, ContentKey, VerificationKeyRing, VerificationStatus,
|
generate_node_hash_key, generate_node_key, generate_node_key_aead, verify_detached,
|
||||||
};
|
};
|
||||||
use proton_sdk::error::{ProtonError, Result};
|
use proton_sdk::error::{ProtonError, Result};
|
||||||
use proton_sdk::http::ApiHttpClient;
|
use proton_sdk::http::ApiHttpClient;
|
||||||
@@ -2430,27 +2430,27 @@ impl ProtonDriveClient {
|
|||||||
// leaves the claimed metadata absent rather than failing the node.
|
// leaves the claimed metadata absent rather than failing the node.
|
||||||
let mut claimed_size = None;
|
let mut claimed_size = None;
|
||||||
let mut claimed_modification_time = None;
|
let mut claimed_modification_time = None;
|
||||||
if let Some(rev) = file.active_revision.as_ref() {
|
if let Some(rev) = file.active_revision.as_ref()
|
||||||
if let Some(xattr) = rev.extended_attributes.as_deref() {
|
&& let Some(xattr) = rev.extended_attributes.as_deref()
|
||||||
match decrypt_extended_attributes_verified(
|
{
|
||||||
&self.account,
|
match decrypt_extended_attributes_verified(
|
||||||
&decrypted.node_key,
|
&self.account,
|
||||||
rev.signature_email.as_deref(),
|
&decrypted.node_key,
|
||||||
xattr,
|
rev.signature_email.as_deref(),
|
||||||
)
|
xattr,
|
||||||
.await
|
)
|
||||||
{
|
.await
|
||||||
Ok((attrs, status)) => {
|
{
|
||||||
verification.extended_attributes = Some(status);
|
Ok((attrs, status)) => {
|
||||||
if let Some(common) = attrs.common {
|
verification.extended_attributes = Some(status);
|
||||||
claimed_size = common.size;
|
if let Some(common) = attrs.common {
|
||||||
claimed_modification_time = common.modification_time;
|
claimed_size = common.size;
|
||||||
}
|
claimed_modification_time = common.modification_time;
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!(link_id = %link.id, error = %e, "failed to decrypt extended attributes");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(link_id = %link.id, error = %e, "failed to decrypt extended attributes");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NodeKind::File {
|
NodeKind::File {
|
||||||
@@ -2520,10 +2520,10 @@ impl ProtonDriveClient {
|
|||||||
uid: &NodeUid,
|
uid: &NodeUid,
|
||||||
link: &LinkDto,
|
link: &LinkDto,
|
||||||
) -> Result<Option<String>> {
|
) -> Result<Option<String>> {
|
||||||
if let Some(info) = self.entities.try_get_node(uid).await? {
|
if let Some(info) = self.entities.try_get_node(uid).await?
|
||||||
if !info.name_hash_digest.is_empty() {
|
&& !info.name_hash_digest.is_empty()
|
||||||
return Ok(Some(info.name_hash_digest));
|
{
|
||||||
}
|
return Ok(Some(info.name_hash_digest));
|
||||||
}
|
}
|
||||||
Ok(link.name_hash.clone())
|
Ok(link.name_hash.clone())
|
||||||
}
|
}
|
||||||
@@ -2768,7 +2768,7 @@ fn verification_token(code: &[u8], ciphertext: &[u8]) -> Vec<u8> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{alternate_names, epoch_to_iso8601, to_drive_event, DriveEvent};
|
use super::{DriveEvent, alternate_names, epoch_to_iso8601, to_drive_event};
|
||||||
use crate::dtos::{VolumeEventDto, VolumeEventLinkDto};
|
use crate::dtos::{VolumeEventDto, VolumeEventLinkDto};
|
||||||
use proton_sdk::ids::{DriveEventId, LinkId, VolumeId};
|
use proton_sdk::ids::{DriveEventId, LinkId, VolumeId};
|
||||||
|
|
||||||
@@ -2866,7 +2866,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn photos_attributes_content_hash_and_tags() {
|
fn photos_attributes_content_hash_and_tags() {
|
||||||
use super::{build_photos_attributes, hmac_sha256, BlockWriteResult};
|
use super::{BlockWriteResult, build_photos_attributes, hmac_sha256};
|
||||||
use crate::photos::{PhotoTag, PhotoUploadMetadata};
|
use crate::photos::{PhotoTag, PhotoUploadMetadata};
|
||||||
use proton_sdk::ids::NodeUid;
|
use proton_sdk::ids::NodeUid;
|
||||||
|
|
||||||
@@ -2902,7 +2902,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn photos_attributes_default_capture_time_and_empty_tags() {
|
fn photos_attributes_default_capture_time_and_empty_tags() {
|
||||||
use super::{build_photos_attributes, BlockWriteResult};
|
use super::{BlockWriteResult, build_photos_attributes};
|
||||||
use crate::photos::PhotoUploadMetadata;
|
use crate::photos::PhotoUploadMetadata;
|
||||||
|
|
||||||
let written = BlockWriteResult {
|
let written = BlockWriteResult {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
use proton_sdk::account::AccountClient;
|
use proton_sdk::account::AccountClient;
|
||||||
use proton_sdk::crypto::{
|
use proton_sdk::crypto::{
|
||||||
decrypt_armored_with_keys, verify_detached, ContentKey, PrivateKey, PublicKey,
|
ContentKey, PrivateKey, PublicKey, VerificationKeyRing, VerificationStatus,
|
||||||
VerificationKeyRing, VerificationStatus,
|
decrypt_armored_with_keys, verify_detached,
|
||||||
};
|
};
|
||||||
use proton_sdk::error::{ProtonError, Result};
|
use proton_sdk::error::{ProtonError, Result};
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ impl NodeVerification {
|
|||||||
};
|
};
|
||||||
ok(self.name)
|
ok(self.name)
|
||||||
&& ok(self.passphrase)
|
&& ok(self.passphrase)
|
||||||
&& self.content_key.map_or(true, ok)
|
&& self.content_key.is_none_or(ok)
|
||||||
&& self.extended_attributes.map_or(true, ok)
|
&& self.extended_attributes.is_none_or(ok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,9 +184,12 @@ async fn node_creation_surfaces_node_updated() {
|
|||||||
.await
|
.await
|
||||||
.expect("create folder");
|
.expect("create folder");
|
||||||
|
|
||||||
let found = poll_for(client, &scope, &cursor, |e| {
|
let found = poll_for(
|
||||||
matches!(e, DriveEvent::NodeUpdated { node_uid, .. } if *node_uid == folder)
|
client,
|
||||||
})
|
&scope,
|
||||||
|
&cursor,
|
||||||
|
|e| matches!(e, DriveEvent::NodeUpdated { node_uid, .. } if *node_uid == folder),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match found {
|
match found {
|
||||||
@@ -282,9 +285,12 @@ async fn permanent_delete_surfaces_node_deleted() {
|
|||||||
.await
|
.await
|
||||||
.expect("delete folder");
|
.expect("delete folder");
|
||||||
|
|
||||||
let found = poll_for(client, &scope, &cursor, |e| {
|
let found = poll_for(
|
||||||
matches!(e, DriveEvent::NodeDeleted { node_uid, .. } if *node_uid == folder)
|
client,
|
||||||
})
|
&scope,
|
||||||
|
&cursor,
|
||||||
|
|e| matches!(e, DriveEvent::NodeDeleted { node_uid, .. } if *node_uid == folder),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
assert!(
|
assert!(
|
||||||
found.is_some(),
|
found.is_some(),
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ mod verify;
|
|||||||
pub use content::ContentKey;
|
pub use content::ContentKey;
|
||||||
pub use derive::derive_key_passphrase;
|
pub use derive::derive_key_passphrase;
|
||||||
pub use encrypt::{
|
pub use encrypt::{
|
||||||
build_volume_creation_material, generate_node_hash_key, generate_node_key,
|
GeneratedNodeKey, VolumeCreationMaterial, build_volume_creation_material,
|
||||||
generate_node_key_aead, GeneratedNodeKey, VolumeCreationMaterial,
|
generate_node_hash_key, generate_node_key, generate_node_key_aead,
|
||||||
};
|
};
|
||||||
pub use errors::CryptoError;
|
pub use errors::CryptoError;
|
||||||
pub use keys::{decrypt_armored_with_keys, PrivateKey};
|
pub use keys::{PrivateKey, decrypt_armored_with_keys};
|
||||||
pub use srp::{generate_proofs, SrpProofs, DEFAULT_BIT_LENGTH};
|
pub use srp::{DEFAULT_BIT_LENGTH, SrpProofs, generate_proofs};
|
||||||
pub use verify::{verify_detached, PublicKey, VerificationKeyRing, VerificationStatus};
|
pub use verify::{PublicKey, VerificationKeyRing, VerificationStatus, verify_detached};
|
||||||
|
|
||||||
/// Result alias for crypto operations.
|
/// Result alias for crypto operations.
|
||||||
pub type CryptoResult<T> = std::result::Result<T, CryptoError>;
|
pub type CryptoResult<T> = std::result::Result<T, CryptoError>;
|
||||||
@@ -19,7 +19,7 @@ use pgp::packet::{
|
|||||||
};
|
};
|
||||||
use pgp::types::{DecryptionKey, EncryptionKey, EskType, PkeskVersion, Seipdv1ReadMode};
|
use pgp::types::{DecryptionKey, EncryptionKey, EskType, PkeskVersion, Seipdv1ReadMode};
|
||||||
|
|
||||||
use super::encrypt::{recipient_encryption_key, RecipientOp};
|
use super::encrypt::{RecipientOp, recipient_encryption_key};
|
||||||
use super::errors::CryptoError;
|
use super::errors::CryptoError;
|
||||||
use super::keys::PrivateKey;
|
use super::keys::PrivateKey;
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ impl ContentKey {
|
|||||||
return Err(CryptoError::Parse(format!(
|
return Err(CryptoError::Parse(format!(
|
||||||
"unexpected thumbnail payload packet: {:?}",
|
"unexpected thumbnail payload packet: {:?}",
|
||||||
other.tag()
|
other.tag()
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ impl ContentKey {
|
|||||||
return Err(CryptoError::Parse(format!(
|
return Err(CryptoError::Parse(format!(
|
||||||
"unexpected block packet: {:?}",
|
"unexpected block packet: {:?}",
|
||||||
other.tag()
|
other.tag()
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
//! signing key with a separate encryption subkey, so recipient selection must
|
//! signing key with a separate encryption subkey, so recipient selection must
|
||||||
//! pick the encryption-capable (sub)key.
|
//! pick the encryption-capable (sub)key.
|
||||||
|
|
||||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use pgp::composed::{
|
use pgp::composed::{
|
||||||
ArmorOptions, DetachedSignature, EncryptionCaps, KeyType, MessageBuilder,
|
ArmorOptions, DetachedSignature, EncryptionCaps, KeyType, MessageBuilder,
|
||||||
@@ -278,11 +278,10 @@ pub(crate) fn sign_detached(signer: &PrivateKey, data: &[u8]) -> Result<String,
|
|||||||
.map_err(|e| CryptoError::Encrypt(format!("creation-time subpacket: {e}")))?,
|
.map_err(|e| CryptoError::Encrypt(format!("creation-time subpacket: {e}")))?,
|
||||||
];
|
];
|
||||||
if key.version() <= KeyVersion::V4 {
|
if key.version() <= KeyVersion::V4 {
|
||||||
config.unhashed_subpackets =
|
config.unhashed_subpackets = vec![
|
||||||
vec![
|
Subpacket::regular(SubpacketData::IssuerKeyId(key.legacy_key_id()))
|
||||||
Subpacket::regular(SubpacketData::IssuerKeyId(key.legacy_key_id()))
|
.map_err(|e| CryptoError::Encrypt(format!("issuer subpacket: {e}")))?,
|
||||||
.map_err(|e| CryptoError::Encrypt(format!("issuer subpacket: {e}")))?,
|
];
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let signature = config
|
let signature = config
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
//! distinct pre-unlock step, so a [`PrivateKey`] simply pairs a parsed
|
//! distinct pre-unlock step, so a [`PrivateKey`] simply pairs a parsed
|
||||||
//! [`SignedSecretKey`] with the passphrase that unlocks it.
|
//! [`SignedSecretKey`] with the passphrase that unlocks it.
|
||||||
|
|
||||||
use pgp::composed::{Deserializable, SignedSecretKey, DetachedSignature};
|
use pgp::composed::{Deserializable, DetachedSignature, SignedSecretKey};
|
||||||
use pgp::types::Password;
|
use pgp::types::Password;
|
||||||
|
|
||||||
use super::errors::CryptoError;
|
use super::errors::CryptoError;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
//! message; we verify the signature against Proton's embedded SRP modulus key
|
//! message; we verify the signature against Proton's embedded SRP modulus key
|
||||||
//! before trusting it.
|
//! before trusting it.
|
||||||
|
|
||||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use num_traits::One;
|
use num_traits::One;
|
||||||
use pgp::composed::{CleartextSignedMessage, Deserializable, SignedPublicKey};
|
use pgp::composed::{CleartextSignedMessage, Deserializable, SignedPublicKey};
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
//! throwing.
|
//! throwing.
|
||||||
|
|
||||||
use pgp::composed::{
|
use pgp::composed::{
|
||||||
Deserializable, Message, SignedPublicKey, SignedSecretKey, DetachedSignature,
|
Deserializable, DetachedSignature, Message, SignedPublicKey, SignedSecretKey,
|
||||||
VerificationResult,
|
VerificationResult,
|
||||||
};
|
};
|
||||||
use pgp::types::{Password, VerifyingKey};
|
use pgp::types::{Password, VerifyingKey};
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use reqwest::{Method, StatusCode};
|
use reqwest::{Method, StatusCode};
|
||||||
use serde::de::DeserializeOwned;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::api::{ApiResponse, ResponseCode};
|
use crate::api::{ApiResponse, ResponseCode};
|
||||||
use crate::config::{ProtonClientConfiguration, RetryPolicy, API_CONTENT_TYPE};
|
use crate::config::{API_CONTENT_TYPE, ProtonClientConfiguration, RetryPolicy};
|
||||||
use crate::error::{ProtonApiError, ProtonError, Result};
|
use crate::error::{ProtonApiError, ProtonError, Result};
|
||||||
use crate::ids::SessionId;
|
use crate::ids::SessionId;
|
||||||
use crate::telemetry::{NoopTelemetry, Telemetry, TelemetryExt};
|
use crate::telemetry::{NoopTelemetry, Telemetry, TelemetryExt};
|
||||||
@@ -674,13 +674,17 @@ mod tests {
|
|||||||
let event = &events[0];
|
let event = &events[0];
|
||||||
assert_eq!(event.operation, "http_request");
|
assert_eq!(event.operation, "http_request");
|
||||||
assert_eq!(event.outcome, Outcome::Success);
|
assert_eq!(event.outcome, Outcome::Success);
|
||||||
assert!(event
|
assert!(
|
||||||
.attributes
|
event
|
||||||
.iter()
|
.attributes
|
||||||
.any(|(k, v)| *k == "method" && v == "GET"));
|
.iter()
|
||||||
assert!(event
|
.any(|(k, v)| *k == "method" && v == "GET")
|
||||||
.attributes
|
);
|
||||||
.iter()
|
assert!(
|
||||||
.any(|(k, v)| *k == "status" && v == "200"));
|
event
|
||||||
|
.attributes
|
||||||
|
.iter()
|
||||||
|
.any(|(k, v)| *k == "status" && v == "200")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
//! deferred, matching the official SDK's stance that login flows live outside
|
//! deferred, matching the official SDK's stance that login flows live outside
|
||||||
//! the core Drive scope.
|
//! the core Drive scope.
|
||||||
|
|
||||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::config::ProtonClientConfiguration;
|
use crate::config::ProtonClientConfiguration;
|
||||||
|
|||||||
Reference in new issue
Block a user