summaryrefslogtreecommitdiffstats
path: root/vendor/crypto-bigint/src/array.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:47:55 +0000
commit2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch)
tree033cc839730fda84ff08db877037977be94e5e3a /vendor/crypto-bigint/src/array.rs
parentInitial commit. (diff)
downloadcargo-upstream.tar.xz
cargo-upstream.zip
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/crypto-bigint/src/array.rs')
-rw-r--r--vendor/crypto-bigint/src/array.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/crypto-bigint/src/array.rs b/vendor/crypto-bigint/src/array.rs
new file mode 100644
index 0000000..3528663
--- /dev/null
+++ b/vendor/crypto-bigint/src/array.rs
@@ -0,0 +1,38 @@
+//! Interop support for `generic-array`
+
+use crate::{Encoding, Integer};
+use core::ops::Add;
+use generic_array::{typenum::Unsigned, ArrayLength, GenericArray};
+
+/// Alias for a byte array whose size is defined by [`ArrayEncoding::ByteSize`].
+pub type ByteArray<T> = GenericArray<u8, <T as ArrayEncoding>::ByteSize>;
+
+/// Support for encoding a big integer as a `GenericArray`.
+pub trait ArrayEncoding: Encoding {
+ /// Size of a byte array which encodes a big integer.
+ type ByteSize: ArrayLength<u8> + Add + Eq + Ord + Unsigned;
+
+ /// Deserialize from a big-endian byte array.
+ fn from_be_byte_array(bytes: ByteArray<Self>) -> Self;
+
+ /// Deserialize from a little-endian byte array.
+ fn from_le_byte_array(bytes: ByteArray<Self>) -> Self;
+
+ /// Serialize to a big-endian byte array.
+ fn to_be_byte_array(&self) -> ByteArray<Self>;
+
+ /// Serialize to a little-endian byte array.
+ fn to_le_byte_array(&self) -> ByteArray<Self>;
+}
+
+/// Support for decoding a `GenericArray` as a big integer.
+pub trait ArrayDecoding {
+ /// Big integer which decodes a `GenericArray`.
+ type Output: ArrayEncoding + Integer;
+
+ /// Deserialize from a big-endian `GenericArray`.
+ fn into_uint_be(self) -> Self::Output;
+
+ /// Deserialize from a little-endian `GenericArray`.
+ fn into_uint_le(self) -> Self::Output;
+}