compact_argon2 0.2.0

Thin wrapper around the argon2 crate to improve ergonomics and provide a smaller serialization format
Documentation
use sqlx::encode::IsNull;
use sqlx::postgres::{PgArgumentBuffer, PgHasArrayType, PgTypeInfo, PgValueRef, Postgres};

use crate::{Hash, OUTPUT_SIZE};

impl sqlx::Type<Postgres> for Hash {
    fn type_info() -> PgTypeInfo { <[u8; 64] as sqlx::Type<Postgres>>::type_info() }
}

impl PgHasArrayType for Hash {
    fn array_type_info() -> PgTypeInfo { <[u8; 64] as PgHasArrayType>::array_type_info() }
}

impl sqlx::Encode<'_, sqlx::Postgres> for Hash {
    fn encode_by_ref(
        &self,
        buf: &mut PgArgumentBuffer,
    ) -> Result<IsNull, sqlx::error::BoxDynError> {
        buf.extend_from_slice(&[0u8; OUTPUT_SIZE]);
        self.write_to_slice(buf.as_mut_slice().try_into()?);
        Ok(IsNull::No)
    }
}

impl sqlx::Decode<'_, sqlx::Postgres> for Hash {
    fn decode(value: PgValueRef) -> Result<Self, sqlx::error::BoxDynError> {
        let bytes = value.as_bytes()?;
        if bytes.len() != OUTPUT_SIZE {
            return Err(format!("stored bytea has incorrect length {}", bytes.len()).into());
        }
        let hash = Hash::try_from(bytes)?;
        Ok(hash)
    }
}