1//! Interop support for `generic-array`
23use crate::{Encoding, Integer};
4use core::ops::Add;
5use generic_array::{typenum::Unsigned, ArrayLength, GenericArray};
67/// Alias for a byte array whose size is defined by [`ArrayEncoding::ByteSize`].
8pub type ByteArray<T> = GenericArray<u8, <T as ArrayEncoding>::ByteSize>;
910/// Support for encoding a big integer as a `GenericArray`.
11pub trait ArrayEncoding: Encoding {
12/// Size of a byte array which encodes a big integer.
13type ByteSize: ArrayLength<u8> + Add + Eq + Ord + Unsigned;
1415/// Deserialize from a big-endian byte array.
16fn from_be_byte_array(bytes: ByteArray<Self>) -> Self;
1718/// Deserialize from a little-endian byte array.
19fn from_le_byte_array(bytes: ByteArray<Self>) -> Self;
2021/// Serialize to a big-endian byte array.
22fn to_be_byte_array(&self) -> ByteArray<Self>;
2324/// Serialize to a little-endian byte array.
25fn to_le_byte_array(&self) -> ByteArray<Self>;
26}
2728/// Support for decoding a `GenericArray` as a big integer.
29pub trait ArrayDecoding {
30/// Big integer which decodes a `GenericArray`.
31type Output: ArrayEncoding + Integer;
3233/// Deserialize from a big-endian `GenericArray`.
34fn into_uint_be(self) -> Self::Output;
3536/// Deserialize from a little-endian `GenericArray`.
37fn into_uint_le(self) -> Self::Output;
38}