localauthentication/
la_credential.rs1use crate::ffi;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[non_exhaustive]
8pub enum LACredentialType {
9 ApplicationPassword,
11 SmartCardPin,
13}
14
15impl LACredentialType {
16 #[must_use]
17 pub const fn raw_value(self) -> i32 {
18 match self {
19 Self::ApplicationPassword => ffi::la_credential::APPLICATION_PASSWORD,
20 Self::SmartCardPin => ffi::la_credential::SMART_CARD_PIN,
21 }
22 }
23
24 pub(crate) const fn as_ffi(self) -> i32 {
25 self.raw_value()
26 }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct LACredential {
32 credential_type: LACredentialType,
33 bytes: Vec<u8>,
34}
35
36impl LACredential {
37 #[must_use]
39 pub fn new(credential_type: LACredentialType, bytes: impl Into<Vec<u8>>) -> Self {
40 Self {
41 credential_type,
42 bytes: bytes.into(),
43 }
44 }
45
46 #[must_use]
48 pub fn application_password(bytes: impl Into<Vec<u8>>) -> Self {
49 Self::new(LACredentialType::ApplicationPassword, bytes)
50 }
51
52 #[must_use]
54 pub fn smart_card_pin(bytes: impl Into<Vec<u8>>) -> Self {
55 Self::new(LACredentialType::SmartCardPin, bytes)
56 }
57
58 #[must_use]
60 pub const fn credential_type(&self) -> LACredentialType {
61 self.credential_type
62 }
63
64 #[must_use]
66 pub fn bytes(&self) -> &[u8] {
67 &self.bytes
68 }
69}