v0.2.5-pre.010.fix.001
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// file: crates/ksp-wallet-lib/src/wire.rs
|
||||
// version: 6
|
||||
// version: 7
|
||||
|
||||
//! Strict native `.kspwallet` V1 wire envelope.
|
||||
|
||||
use base64::Engine; // rust-rules: derive-import
|
||||
use base64::Engine; // rust-rules: trait-import
|
||||
|
||||
/// Password KDF supported by `.kspwallet` V1 key slots.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
@@ -105,6 +105,7 @@ pub struct WalletKdfParametersV1 {
|
||||
}
|
||||
|
||||
impl WalletKdfParametersV1 {
|
||||
/// Creates a new creation value for `WalletKdfParametersV1`.
|
||||
pub(crate) fn new_creation(salt: std::vec::Vec<u8>) -> Self {
|
||||
return Self {
|
||||
algorithm: WalletKdfAlgorithmV1::Argon2id,
|
||||
@@ -176,6 +177,7 @@ pub struct WalletKeyWrapV1 {
|
||||
}
|
||||
|
||||
impl WalletKeyWrapV1 {
|
||||
/// Creates a new `WalletKeyWrapV1` value.
|
||||
pub(crate) fn new(nonce: [u8; crate::KSPWALLET_V1_XCHACHA_NONCE_BYTES], ciphertext: std::vec::Vec<u8>) -> Self {
|
||||
return Self { algorithm: WalletAeadAlgorithmV1::XChaCha20Poly1305, nonce, ciphertext };
|
||||
}
|
||||
@@ -220,6 +222,7 @@ pub struct WalletKeySlotV1 {
|
||||
}
|
||||
|
||||
impl WalletKeySlotV1 {
|
||||
/// Creates a new `WalletKeySlotV1` value.
|
||||
pub(crate) fn new(slot_id: [u8; crate::KSPWALLET_V1_SLOT_ID_BYTES], role: WalletKeySlotRoleV1, kdf: WalletKdfParametersV1, wrap: WalletKeyWrapV1) -> Self {
|
||||
return Self { slot_id, role, kdf, wrap };
|
||||
}
|
||||
@@ -269,10 +272,12 @@ pub struct WalletViewDescriptorV1 {
|
||||
}
|
||||
|
||||
impl WalletViewDescriptorV1 {
|
||||
/// Executes the crate-internal disabled operation for `WalletViewDescriptorV1`.
|
||||
pub(crate) const fn disabled() -> Self {
|
||||
return Self { enabled: false, slot_id: std::option::Option::None };
|
||||
}
|
||||
|
||||
/// Executes the crate-internal enabled for slot operation for `WalletViewDescriptorV1`.
|
||||
pub(crate) const fn enabled_for_slot(slot_id: [u8; crate::KSPWALLET_V1_SLOT_ID_BYTES]) -> Self {
|
||||
return Self { enabled: true, slot_id: std::option::Option::Some(slot_id) };
|
||||
}
|
||||
@@ -301,6 +306,7 @@ pub struct WalletEncryptedCompartmentV1 {
|
||||
}
|
||||
|
||||
impl WalletEncryptedCompartmentV1 {
|
||||
/// Creates a new `WalletEncryptedCompartmentV1` value.
|
||||
pub(crate) fn new(kind: WalletCompartmentKindV1, nonce: [u8; crate::KSPWALLET_V1_XCHACHA_NONCE_BYTES], ciphertext: std::vec::Vec<u8>) -> Self {
|
||||
return Self {
|
||||
kind,
|
||||
@@ -363,6 +369,7 @@ pub struct WalletStateSignatureV1 {
|
||||
}
|
||||
|
||||
impl WalletStateSignatureV1 {
|
||||
/// Creates a new `WalletStateSignatureV1` value.
|
||||
pub(crate) const fn new(signature: [u8; crate::KSPWALLET_V1_ED25519_SIGNATURE_BYTES]) -> Self {
|
||||
return Self { algorithm: WalletStateSignatureAlgorithmV1::Ed25519, signature };
|
||||
}
|
||||
@@ -404,6 +411,7 @@ pub struct KspWalletEnvelopeV1 {
|
||||
}
|
||||
|
||||
impl KspWalletEnvelopeV1 {
|
||||
/// Creates a new internal value for `KspWalletEnvelopeV1`.
|
||||
pub(crate) fn new_internal(
|
||||
owner_auth_public_key: [u8; crate::KSPWALLET_V1_ED25519_PUBLIC_KEY_BYTES],
|
||||
view_descriptor: WalletViewDescriptorV1,
|
||||
@@ -434,7 +442,6 @@ impl KspWalletEnvelopeV1 {
|
||||
if source.len() > crate::KSPWALLET_MAX_FILE_BYTES {
|
||||
return std::result::Result::Err(format_error("Wallet document exceeds the V1 maximum size", "document"));
|
||||
}
|
||||
|
||||
let probe_result = serde_json::from_slice::<RawVersionProbe>(source);
|
||||
let probe = match probe_result {
|
||||
std::result::Result::Ok(probe) => probe,
|
||||
@@ -449,7 +456,6 @@ impl KspWalletEnvelopeV1 {
|
||||
.with_context("format_version", probe.format_version.to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
let raw_result = serde_json::from_slice::<RawEnvelopeV1>(source);
|
||||
let raw = match raw_result {
|
||||
std::result::Result::Ok(raw) => raw,
|
||||
@@ -793,7 +799,6 @@ fn parse_raw_envelope(raw: RawEnvelopeV1) -> ksp_core_lib::Result<KspWalletEnvel
|
||||
.with_context("format_version", raw.format_version.to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
let owner_auth_public_key =
|
||||
match decode_fixed::<{ crate::KSPWALLET_V1_ED25519_PUBLIC_KEY_BYTES }>(raw.owner_auth_public_key.as_str(), "owner_auth_public_key") {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -803,7 +808,6 @@ fn parse_raw_envelope(raw: RawEnvelopeV1) -> ksp_core_lib::Result<KspWalletEnvel
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
|
||||
if raw.key_slots.is_empty() || raw.key_slots.len() > crate::KSPWALLET_V1_MAX_KEY_SLOTS {
|
||||
return std::result::Result::Err(format_error("Wallet key_slots count is invalid for V1", "key_slots"));
|
||||
}
|
||||
@@ -853,7 +857,6 @@ fn parse_raw_envelope(raw: RawEnvelopeV1) -> ksp_core_lib::Result<KspWalletEnvel
|
||||
} else if view_slot.is_some() {
|
||||
return std::result::Result::Err(format_error("Disabled VIEW descriptor forbids a VIEW key slot", "key_slots"));
|
||||
}
|
||||
|
||||
let owner_control = match parse_compartment(
|
||||
WalletCompartmentKindV1::OwnerControl,
|
||||
raw.owner_control.control_version,
|
||||
@@ -891,7 +894,6 @@ fn parse_raw_envelope(raw: RawEnvelopeV1) -> ksp_core_lib::Result<KspWalletEnvel
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
|
||||
return std::result::Result::Ok(KspWalletEnvelopeV1 {
|
||||
owner_auth_public_key,
|
||||
view_descriptor,
|
||||
|
||||
Reference in New Issue
Block a user