Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions der/src/asn1/bit_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ impl Iterator for BitStringIter<'_> {
self.position = self.position.checked_add(1)?;
Some(byte & bit != 0)
}

fn size_hint(&self) -> (usize, Option<usize>) {
Comment thread
baloo marked this conversation as resolved.
let len = self.bit_string.bit_len().saturating_sub(self.position);
(len, Some(len))
}
}

impl ExactSizeIterator for BitStringIter<'_> {
Expand Down Expand Up @@ -569,6 +574,8 @@ where
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use core::cmp::Ordering;

use super::{BitStringRef, Result, Tag};
use crate::asn1::AnyRef;
use hex_literal::hex;
Expand Down Expand Up @@ -616,4 +623,13 @@ mod tests {
Tag::BitString.value_error().kind()
)
}

#[test]
fn bitstring_valueord_value_cmp() {
use crate::ord::DerOrd;

let bs1 = parse_bitstring(&hex!("00010204")).unwrap();
let bs2 = parse_bitstring(&hex!("00010203")).unwrap();
assert_eq!(bs1.der_cmp(&bs2), Ok(Ordering::Greater));
}
}
29 changes: 29 additions & 0 deletions der/src/asn1/sequence_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ impl<'a, T> Iterator for SequenceOfIter<'a, T> {
fn next(&mut self) -> Option<&'a T> {
self.inner.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
Comment thread
baloo marked this conversation as resolved.
self.inner.size_hint()
}
}

impl<T> ExactSizeIterator for SequenceOfIter<'_, T> {}
Expand Down Expand Up @@ -239,3 +243,28 @@ where
iter_cmp(self.iter(), other.iter())
}
}

#[cfg(test)]
mod tests {
use crate::asn1::SequenceOf;
use crate::ord::DerOrd;

#[test]
fn sequenceof_valueord_value_cmp() {
use core::cmp::Ordering;

let arr1 = {
let mut arr: SequenceOf<u16, 2> = SequenceOf::new();
arr.add(0u16).expect("element to be added");
arr.add(2u16).expect("element to be added");
arr
};
let arr2 = {
let mut arr: SequenceOf<u16, 2> = SequenceOf::new();
arr.add(0u16).expect("element to be added");
arr.add(1u16).expect("element to be added");
arr
};
assert_eq!(arr1.der_cmp(&arr2), Ok(Ordering::Greater));
}
}
17 changes: 16 additions & 1 deletion der/src/asn1/set_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ impl<'a, T> Iterator for SetOfIter<'a, T> {
fn next(&mut self) -> Option<&'a T> {
self.inner.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

impl<T> ExactSizeIterator for SetOfIter<'_, T> {}
Expand Down Expand Up @@ -478,7 +482,7 @@ mod tests {
use super::SetOf;
#[cfg(feature = "alloc")]
use super::SetOfVec;
use crate::ErrorKind;
use crate::{DerOrd, ErrorKind};

#[test]
fn setof_tryfrom_array() {
Expand All @@ -494,6 +498,17 @@ mod tests {
assert_eq!(err.kind(), ErrorKind::SetDuplicate);
}

#[test]
fn setof_valueord_value_cmp() {
use core::cmp::Ordering;

let arr1 = [3u16, 2, 1, 5, 0];
let arr2 = [3u16, 2, 1, 4, 0];
let set1 = SetOf::try_from(arr1).unwrap();
let set2 = SetOf::try_from(arr2).unwrap();
assert_eq!(set1.der_cmp(&set2), Ok(Ordering::Greater));
}

#[cfg(feature = "alloc")]
#[test]
fn setofvec_tryfrom_array() {
Expand Down