cert rdn: fix struct hierarchy
This commit is contained in:
parent
65220dbb46
commit
7229a56eef
@ -328,7 +328,7 @@ pub struct AlgorithmIdentifier<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Name<'a> {
|
pub struct Name<'a> {
|
||||||
pub relative_distinguished_name: Vec<AttributeTypeAndValue<'a>>
|
pub relative_distinguished_name: Vec<RelativeDistinguishedName<'a>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PartialEq for Name<'a> {
|
impl<'a> PartialEq for Name<'a> {
|
||||||
@ -344,6 +344,11 @@ impl<'a> PartialEq for Name<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub struct RelativeDistinguishedName<'a> {
|
||||||
|
pub type_and_attributes: Vec<AttributeTypeAndValue<'a>>
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct AttributeTypeAndValue<'a> {
|
pub struct AttributeTypeAndValue<'a> {
|
||||||
pub attribute_type: &'a [u8], // OID
|
pub attribute_type: &'a [u8], // OID
|
||||||
|
61
src/parse.rs
61
src/parse.rs
@ -18,20 +18,21 @@ use byteorder::{ByteOrder, NetworkEndian};
|
|||||||
use crate::tls_packet::*;
|
use crate::tls_packet::*;
|
||||||
|
|
||||||
use crate::certificate::{
|
use crate::certificate::{
|
||||||
Certificate as Asn1DerCertificate,
|
Certificate as Asn1DerCertificate,
|
||||||
Version as Asn1DerVersion,
|
Version as Asn1DerVersion,
|
||||||
AlgorithmIdentifier as Asn1DerAlgId,
|
AlgorithmIdentifier as Asn1DerAlgId,
|
||||||
Time as Asn1DerTime,
|
Time as Asn1DerTime,
|
||||||
Validity as Asn1DerValidity,
|
Validity as Asn1DerValidity,
|
||||||
SubjectPublicKeyInfo as Asn1DerSubjectPublicKeyInfo,
|
SubjectPublicKeyInfo as Asn1DerSubjectPublicKeyInfo,
|
||||||
Extensions as Asn1DerExtensions,
|
Extensions as Asn1DerExtensions,
|
||||||
Extension as Asn1DerExtension,
|
Extension as Asn1DerExtension,
|
||||||
ExtensionValue as Asn1DerExtensionValue,
|
ExtensionValue as Asn1DerExtensionValue,
|
||||||
PolicyInformation as Asn1DerPolicyInformation,
|
PolicyInformation as Asn1DerPolicyInformation,
|
||||||
TBSCertificate as Asn1DerTBSCertificate,
|
TBSCertificate as Asn1DerTBSCertificate,
|
||||||
Name as Asn1DerName,
|
Name as Asn1DerName,
|
||||||
AttributeTypeAndValue as Asn1DerAttribute,
|
AttributeTypeAndValue as Asn1DerAttribute,
|
||||||
GeneralName as Asn1DerGeneralName,
|
GeneralName as Asn1DerGeneralName,
|
||||||
|
RelativeDistinguishedName as Asn1DerRDN,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::oid;
|
use crate::oid;
|
||||||
@ -812,10 +813,10 @@ pub fn parse_asn1_der_oid(bytes: &[u8]) -> IResult<&[u8], &[u8]> {
|
|||||||
// Parser for Name, applicable to issuer and subject field of TBS cert.
|
// Parser for Name, applicable to issuer and subject field of TBS cert.
|
||||||
pub fn parse_asn1_der_name(bytes: &[u8]) -> IResult<&[u8], Asn1DerName> {
|
pub fn parse_asn1_der_name(bytes: &[u8]) -> IResult<&[u8], Asn1DerName> {
|
||||||
let (rest, mut rdn_sequence) = parse_asn1_der_sequence(bytes)?;
|
let (rest, mut rdn_sequence) = parse_asn1_der_sequence(bytes)?;
|
||||||
let mut attributes_vec: Vec<Asn1DerAttribute> = Vec::new();
|
let mut attributes_vec: Vec<Asn1DerRDN> = Vec::new();
|
||||||
|
|
||||||
while rdn_sequence.len() != 0 {
|
while rdn_sequence.len() != 0 {
|
||||||
let (rem, attribute) = parse_asn1_der_attribute_type_and_value(
|
let (rem, attribute) = parse_asn1_der_relative_distinguished_name(
|
||||||
rdn_sequence
|
rdn_sequence
|
||||||
)?;
|
)?;
|
||||||
rdn_sequence = rem;
|
rdn_sequence = rem;
|
||||||
@ -830,19 +831,37 @@ pub fn parse_asn1_der_name(bytes: &[u8]) -> IResult<&[u8], Asn1DerName> {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parser for Relative Distinguished Name (RDN)
|
||||||
|
pub fn parse_asn1_der_relative_distinguished_name(bytes: &[u8]) -> IResult<&[u8], Asn1DerRDN> {
|
||||||
|
let (rest, mut attribute_set) = parse_asn1_der_set(bytes)?;
|
||||||
|
let mut attributes_vec: Vec<Asn1DerAttribute> = Vec::new();
|
||||||
|
|
||||||
|
while attribute_set.len() != 0 {
|
||||||
|
let (rem, attribute) = parse_asn1_der_attribute_type_and_value(
|
||||||
|
attribute_set
|
||||||
|
)?;
|
||||||
|
attribute_set = rem;
|
||||||
|
attributes_vec.push(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
rest,
|
||||||
|
Asn1DerRDN {
|
||||||
|
type_and_attributes: attributes_vec
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
// Parser for AttributeTypeAndValue struct, typically wrapped inside Name struct
|
// Parser for AttributeTypeAndValue struct, typically wrapped inside Name struct
|
||||||
pub fn parse_asn1_der_attribute_type_and_value(bytes: &[u8]) -> IResult<&[u8], Asn1DerAttribute> {
|
pub fn parse_asn1_der_attribute_type_and_value(bytes: &[u8]) -> IResult<&[u8], Asn1DerAttribute> {
|
||||||
let (rest, set) = parse_asn1_der_set(bytes)?;
|
let (rest, set) = parse_asn1_der_sequence(bytes)?;
|
||||||
let (_, attribute) = complete(
|
|
||||||
parse_asn1_der_sequence
|
|
||||||
)(set)?;
|
|
||||||
|
|
||||||
let (_, (oid, (tag_val, _, value))) = complete(
|
let (_, (oid, (tag_val, _, value))) = complete(
|
||||||
tuple((
|
tuple((
|
||||||
parse_asn1_der_oid,
|
parse_asn1_der_oid,
|
||||||
parse_asn1_der_object
|
parse_asn1_der_object
|
||||||
))
|
))
|
||||||
)(attribute)?;
|
)(set)?;
|
||||||
|
|
||||||
// Verify that tag_val is either "PrintableString or UTF8String"
|
// Verify that tag_val is either "PrintableString or UTF8String"
|
||||||
if tag_val != 0x13 && tag_val != 0x0C {
|
if tag_val != 0x13 && tag_val != 0x0C {
|
||||||
|
Loading…
Reference in New Issue
Block a user