Return error instead of panics on invalid ASN.1 #9

Merged
Flakebi merged 4 commits from master into master 2019-03-29 16:20:13 -07:00
Showing only changes of commit 8a64254c95 - Show all commits

View File

@@ -374,6 +374,9 @@ fn from_der_(i: &[u8], start_offset: usize)
let soff = start_offset + index; let soff = start_offset + index;
let (tag, constructed, class) = decode_tag(i, &mut index); let (tag, constructed, class) = decode_tag(i, &mut index);
let len = decode_length(i, &mut index)?; let len = decode_length(i, &mut index)?;
if i.len() < index + len {
return Err(ASN1DecodeErr::LengthTooLarge(index + len));
}
let body = &i[index .. (index + len)]; let body = &i[index .. (index + len)];
if class != ASN1Class::Universal { if class != ASN1Class::Universal {