armour-core 0.1.2

Core types for armour ecosystem
Documentation
#![warn(clippy::unwrap_used)]

pub mod enc;
pub mod error;
pub mod fuid;
pub mod get_type;
pub mod id64;
pub mod key_part;
pub mod key_type;
pub mod num_ops;
pub mod record_status;
pub mod typ;
pub mod zbase;

#[cfg(feature = "std")]
pub mod persist;

use arrayvec::ArrayString;

pub use armour_derive::*;
pub use error::ArmourError;
pub use fuid::Fuid;
pub use get_type::GetType;
pub use id64::Id64;
pub use key_type::{KeyScheme, KeyType};
pub use typ::{EnumType, Fields, SimpleEnumType, StructType, Typ};

/// Compatibility module for armour-derive generated code paths.
pub mod dyn_types {
    pub use crate::get_type;
    pub use crate::typ::{EnumType, Fields, SimpleEnumType, StructType, Typ};
}

pub type IdStr = ArrayString<13>;

pub type Result<T, E = ArmourError> = core::result::Result<T, E>;

/// key should be Base64Url decoded 56 bytes long (~ 75 chars)
///
/// `const_hasher!(module_name, "KEY_ENV_NAME");`
///
/// env name concatenated with "APP_ID_KEY_" will be used to get the key
#[macro_export]
macro_rules! const_hasher {
    ($m_name: ident, $key_name: literal) => {
        pub mod $m_name {
            use $crate::enc::{Cipher, IdHasher};

            #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Hash)]
            pub struct Hasher;

            impl IdHasher for Hasher {
                const HASHER: Cipher = Cipher::new(env!(concat!("APP_ID_KEY_", $key_name)));
            }
        }
    };
}

/// key should be Base64Url decoded 56 bytes long (~ 75 chars)
///
/// `hasher!(module_name, "_mKbKGF2IrkGvIJvl97HuCgWjgt6QRZ7Ye8DHBQ2anvyi18BdMz8uN6Ej3YJApooY6qDu0obqq4");`
#[macro_export]
macro_rules! hasher {
    ($m_name: ident, $key: literal) => {
        pub mod $m_name {
            use $crate::enc::{Cipher, IdHasher};

            #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Hash)]
            pub struct Hasher;

            impl IdHasher for Hasher {
                const HASHER: Cipher = Cipher::new($key);
            }
        }
    };
}