summaryrefslogtreecommitdiffstats
path: root/vendor/block-buffer/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/block-buffer/src
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/block-buffer/src')
-rw-r--r--vendor/block-buffer/src/lib.rs41
-rw-r--r--vendor/block-buffer/src/sealed.rs2
2 files changed, 34 insertions, 9 deletions
diff --git a/vendor/block-buffer/src/lib.rs b/vendor/block-buffer/src/lib.rs
index ebe736959..441621e93 100644
--- a/vendor/block-buffer/src/lib.rs
+++ b/vendor/block-buffer/src/lib.rs
@@ -2,14 +2,13 @@
#![no_std]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
- html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
- html_root_url = "https://docs.rs/block-buffer/0.10.2"
+ html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
)]
#![warn(missing_docs, rust_2018_idioms)]
pub use generic_array;
-use core::{marker::PhantomData, slice};
+use core::{fmt, marker::PhantomData, slice};
use generic_array::{
typenum::{IsLess, Le, NonZero, U256},
ArrayLength, GenericArray,
@@ -41,6 +40,16 @@ pub type EagerBuffer<B> = BlockBuffer<B, Eager>;
/// Lazy block buffer.
pub type LazyBuffer<B> = BlockBuffer<B, Lazy>;
+/// Block buffer error.
+#[derive(Copy, Clone, Eq, PartialEq, Debug)]
+pub struct Error;
+
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
+ f.write_str("Block buffer error")
+ }
+}
+
/// Buffer for block processing of data.
#[derive(Debug)]
pub struct BlockBuffer<BlockSize, Kind>
@@ -61,6 +70,9 @@ where
Kind: BufferKind,
{
fn default() -> Self {
+ if BlockSize::USIZE == 0 {
+ panic!("Block size can not be equal to zero");
+ }
Self {
buffer: Default::default(),
pos: 0,
@@ -96,15 +108,28 @@ where
/// If slice length is not valid for used buffer kind.
#[inline(always)]
pub fn new(buf: &[u8]) -> Self {
+ Self::try_new(buf).unwrap()
+ }
+
+ /// Create new buffer from slice.
+ ///
+ /// Returns an error if slice length is not valid for used buffer kind.
+ #[inline(always)]
+ pub fn try_new(buf: &[u8]) -> Result<Self, Error> {
+ if BlockSize::USIZE == 0 {
+ panic!("Block size can not be equal to zero");
+ }
let pos = buf.len();
- assert!(Kind::invariant(pos, BlockSize::USIZE));
+ if !Kind::invariant(pos, BlockSize::USIZE) {
+ return Err(Error);
+ }
let mut buffer = Block::<BlockSize>::default();
buffer[..pos].copy_from_slice(buf);
- Self {
+ Ok(Self {
buffer,
pos: pos as u8,
_pd: PhantomData,
- }
+ })
}
/// Digest data in `input` in blocks of size `BlockSize` using
@@ -196,13 +221,13 @@ where
self.set_pos_unchecked(pos);
}
- /// Return size of the internall buffer in bytes.
+ /// Return size of the internal buffer in bytes.
#[inline(always)]
pub fn size(&self) -> usize {
BlockSize::USIZE
}
- /// Return number of remaining bytes in the internall buffer.
+ /// Return number of remaining bytes in the internal buffer.
#[inline(always)]
pub fn remaining(&self) -> usize {
self.size() - self.get_pos()
diff --git a/vendor/block-buffer/src/sealed.rs b/vendor/block-buffer/src/sealed.rs
index 371a8b703..247dec233 100644
--- a/vendor/block-buffer/src/sealed.rs
+++ b/vendor/block-buffer/src/sealed.rs
@@ -7,7 +7,7 @@ pub trait Sealed {
/// buffer code this function always returns true.
fn invariant(pos: usize, block_size: usize) -> bool;
- /// Split input data into slice fo blocks and tail.
+ /// Split input data into slice of blocks and tail.
fn split_blocks<N: ArrayLength<u8>>(data: &[u8]) -> (&[Block<N>], &[u8]);
}