argon2/
version.rs

1//! Version of the algorithm.
2
3use crate::{Error, Result};
4
5/// Version of the algorithm.
6#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
7#[repr(u32)]
8pub enum Version {
9    /// Version 16 (0x10 in hex)
10    ///
11    /// Performs overwrite internally
12    V0x10 = 0x10,
13
14    /// Version 19 (0x13 in hex, default)
15    ///
16    /// Performs XOR internally
17    #[default]
18    V0x13 = 0x13,
19}
20
21impl Version {
22    /// Serialize version as little endian bytes
23    pub(crate) const fn to_le_bytes(self) -> [u8; 4] {
24        (self as u32).to_le_bytes()
25    }
26}
27
28impl From<Version> for u32 {
29    fn from(version: Version) -> u32 {
30        version as u32
31    }
32}
33
34impl TryFrom<u32> for Version {
35    type Error = Error;
36
37    fn try_from(version_id: u32) -> Result<Version> {
38        match version_id {
39            0x10 => Ok(Version::V0x10),
40            0x13 => Ok(Version::V0x13),
41            _ => Err(Error::VersionInvalid),
42        }
43    }
44}