Skip to content

Commit

Permalink
Merge branch '78-bitflags'
Browse files Browse the repository at this point in the history
Fixes #82
  • Loading branch information
szszszsz committed May 25, 2023
2 parents 169cf29 + baf433a commit 05eba89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde = { version = "1", default-features = false }
trussed = { version = "0.1", features = ["clients-3"] }
encrypted_container = { path = "components/encrypted_container" }
block-padding = "0.3.3"
bitflags = "2.3.1"

# extension
trussed-auth = "0.2.0"
Expand Down
42 changes: 29 additions & 13 deletions src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,37 @@ impl Default for CredentialFlat {
}
}

use bitflags::bitflags;

bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
struct PropertiesByte: u8 {
const touch_required = 1 << 0;
const encrypted = 1 << 1;
const pws_data_exist = 1 << 2;
}
}

impl From<&CredentialFlat> for PropertiesByte {
fn from(cred: &CredentialFlat) -> Self {
let mut res: PropertiesByte = PropertiesByte::empty();
if cred.touch_required {
res |= PropertiesByte::touch_required;
}
if cred.encryption_key_type.unwrap() == EncryptionKeyType::PinBased {
res |= PropertiesByte::encrypted;
}
if cred.login.is_some() || cred.password.is_some() {
res |= PropertiesByte::pws_data_exist;
}
res
}
}

impl CredentialFlat {
pub fn get_properties_byte(&self) -> u8 {
let mut res: u8 = 0;
res |= if self.touch_required { 1 << 0 } else { 0 };
res |= if self.encryption_key_type.unwrap() == EncryptionKeyType::PinBased {
1 << 1
} else {
0
};
res |= if self.login.is_some() || self.password.is_some() {
1 << 2
} else {
0
};
res
let res: PropertiesByte = self.into();
res.bits()
}

fn get_bytes_or_none_if_empty(x: &[u8]) -> Result<Option<ShortData>, ()> {
Expand Down

0 comments on commit 05eba89

Please sign in to comment.