diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/der/src/asn1/real.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/der/src/asn1/real.rs')
-rw-r--r-- | vendor/der/src/asn1/real.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/vendor/der/src/asn1/real.rs b/vendor/der/src/asn1/real.rs index f872d2d0b..b9f2e67f5 100644 --- a/vendor/der/src/asn1/real.rs +++ b/vendor/der/src/asn1/real.rs @@ -8,22 +8,21 @@ )] use crate::{ - str_slice::StrSlice, ByteSlice, DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, - Result, Tag, Writer, + BytesRef, DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, Result, StrRef, Tag, + Writer, }; use super::integer::uint::strip_leading_zeroes; -#[cfg_attr(docsrs, doc(cfg(feature = "real")))] impl<'a> DecodeValue<'a> for f64 { fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> { - let bytes = ByteSlice::decode_value(reader, header)?.as_slice(); + let bytes = BytesRef::decode_value(reader, header)?.as_slice(); if header.length == Length::ZERO { Ok(0.0) } else if is_nth_bit_one::<7>(bytes) { // Binary encoding from section 8.5.7 applies - let sign: u64 = if is_nth_bit_one::<6>(bytes) { 1 } else { 0 }; + let sign: u64 = u64::from(is_nth_bit_one::<6>(bytes)); // Section 8.5.7.2: Check the base -- the DER specs say that only base 2 should be supported in DER let base = mnth_bits_to_u8::<5, 4>(bytes); @@ -74,7 +73,7 @@ impl<'a> DecodeValue<'a> for f64 { _ => Err(Tag::Real.value_error()), } } else { - let astr = StrSlice::from_bytes(&bytes[1..])?; + let astr = StrRef::from_bytes(&bytes[1..])?; match astr.inner.parse::<f64>() { Ok(val) => Ok(val), // Real related error: encoding not supported or malformed @@ -84,7 +83,6 @@ impl<'a> DecodeValue<'a> for f64 { } } -#[cfg_attr(docsrs, doc(cfg(feature = "real")))] impl EncodeValue for f64 { fn value_len(&self) -> Result<Length> { if self.is_sign_positive() && (*self) < f64::MIN_POSITIVE { @@ -120,7 +118,7 @@ impl EncodeValue for f64 { } } - fn encode_value(&self, writer: &mut dyn Writer) -> Result<()> { + fn encode_value(&self, writer: &mut impl Writer) -> Result<()> { // Check if special value // Encode zero first, if it's zero // Special value from section 8.5.9 if non zero @@ -194,7 +192,6 @@ impl EncodeValue for f64 { } } -#[cfg_attr(docsrs, doc(cfg(feature = "real")))] impl FixedTag for f64 { const TAG: Tag = Tag::Real; } @@ -204,7 +201,7 @@ impl FixedTag for f64 { pub(crate) fn is_nth_bit_one<const N: usize>(bytes: &[u8]) -> bool { if N < 8 { bytes - .get(0) + .first() .map(|byte| byte & (1 << N) != 0) .unwrap_or(false) } else { |