Add default user profile id
Some checks failed
Sharenet Passport CI / test-native (push) Has been cancelled
Sharenet Passport CI / test-wasm-headless (push) Has been cancelled
Sharenet Passport CI / test-wasm-webdriver (push) Has been cancelled
Sharenet Passport CI / build-wasm (push) Has been cancelled
Sharenet Passport CI / lint (push) Has been cancelled
Sharenet Passport CI / test-native (pull_request) Has been cancelled
Sharenet Passport CI / test-wasm-headless (pull_request) Has been cancelled
Sharenet Passport CI / test-wasm-webdriver (pull_request) Has been cancelled
Sharenet Passport CI / build-wasm (pull_request) Has been cancelled
Sharenet Passport CI / lint (pull_request) Has been cancelled

This commit is contained in:
Continuist 2025-10-31 14:56:52 -04:00
parent bd4c3ac3ab
commit 7407f5ac09

View file

@ -92,6 +92,7 @@ impl FileEncryptor for XChaCha20FileEncryptor {
univ_id: &str, univ_id: &str,
user_profiles: &[UserProfile], user_profiles: &[UserProfile],
date_of_birth: &Option<DateOfBirth>, date_of_birth: &Option<DateOfBirth>,
default_user_profile_id: &Option<String>,
) -> Result<PassportFile, Self::Error> { ) -> Result<PassportFile, Self::Error> {
// Generate salt and nonce using WASM-compatible RNG // Generate salt and nonce using WASM-compatible RNG
let mut salt = [0u8; SALT_LENGTH]; let mut salt = [0u8; SALT_LENGTH];
@ -128,6 +129,13 @@ impl FileEncryptor for XChaCha20FileEncryptor {
.encrypt(&nonce, &*date_of_birth_bytes) .encrypt(&nonce, &*date_of_birth_bytes)
.map_err(|e| DomainError::CryptographicError(format!("Date of birth encryption failed: {}", e)))?; .map_err(|e| DomainError::CryptographicError(format!("Date of birth encryption failed: {}", e)))?;
// Serialize and encrypt default user profile ID
let default_user_profile_id_bytes = serde_cbor::to_vec(&default_user_profile_id)
.map_err(|e| DomainError::CryptographicError(format!("Failed to serialize default user profile ID: {}", e)))?;
let enc_default_user_profile_id = cipher
.encrypt(&nonce, &*default_user_profile_id_bytes)
.map_err(|e| DomainError::CryptographicError(format!("Default user profile ID encryption failed: {}", e)))?;
// Get current timestamp using WASM-compatible time // Get current timestamp using WASM-compatible time
let created_at = time::now_seconds()?; let created_at = time::now_seconds()?;
@ -144,6 +152,7 @@ impl FileEncryptor for XChaCha20FileEncryptor {
version: "1.0.0".to_string(), version: "1.0.0".to_string(),
enc_user_profiles, enc_user_profiles,
enc_date_of_birth, enc_date_of_birth,
enc_default_user_profile_id,
}) })
} }
@ -151,7 +160,7 @@ impl FileEncryptor for XChaCha20FileEncryptor {
&self, &self,
file: &PassportFile, file: &PassportFile,
password: &str, password: &str,
) -> Result<(Seed, PublicKey, PrivateKey, Vec<UserProfile>, Option<DateOfBirth>), Self::Error> { ) -> Result<(Seed, PublicKey, PrivateKey, Vec<UserProfile>, Option<DateOfBirth>, Option<String>), Self::Error> {
// Validate file format // Validate file format
validate_file_format(&file.kdf, &file.cipher)?; validate_file_format(&file.kdf, &file.cipher)?;
@ -195,7 +204,14 @@ impl FileEncryptor for XChaCha20FileEncryptor {
let date_of_birth: Option<DateOfBirth> = serde_cbor::from_slice(&date_of_birth_bytes) let date_of_birth: Option<DateOfBirth> = serde_cbor::from_slice(&date_of_birth_bytes)
.map_err(|e| DomainError::CryptographicError(format!("Failed to deserialize date of birth: {}", e)))?; .map_err(|e| DomainError::CryptographicError(format!("Failed to deserialize date of birth: {}", e)))?;
// Decrypt default user profile ID
let default_user_profile_id_bytes = cipher
.decrypt(&nonce, &*file.enc_default_user_profile_id)
.map_err(|e| DomainError::CryptographicError(format!("Default user profile ID decryption failed: {}", e)))?;
let default_user_profile_id: Option<String> = serde_cbor::from_slice(&default_user_profile_id_bytes)
.map_err(|e| DomainError::CryptographicError(format!("Failed to deserialize default user profile ID: {}", e)))?;
// Note: univ_id is stored in the PassportFile and will be used when creating the Passport // Note: univ_id is stored in the PassportFile and will be used when creating the Passport
Ok((seed, public_key, private_key, user_profiles, date_of_birth)) Ok((seed, public_key, private_key, user_profiles, date_of_birth, default_user_profile_id))
} }
} }