util/oid.go
func GetMappedPolicies(polMap *pkix.Extension) (out [][2]asn1.ObjectIdentifier, err error) {
	if polMap == nil {
		return nil, errors.New("policyMap: null pointer")
	}
	var outSeq, inSeq asn1.RawValue

	empty, err := asn1.Unmarshal(polMap.Value, &outSeq) //strip outer sequence tag/length should be nothing extra
	if err != nil || len(empty) != 0 || outSeq.Class != 0 || outSeq.Tag != 16 || outSeq.IsCompound == false {
		return nil, errors.New("policyMap: Could not unmarshal outer sequence.")
	}

	for done := false; !done; { //loop through SEQUENCE OF
		outSeq.Bytes, err = asn1.Unmarshal(outSeq.Bytes, &inSeq) //extract next inner SEQUENCE (OID pair)
		if err != nil || inSeq.Class != 0 || inSeq.Tag != 16 || inSeq.IsCompound == false {
			err = errors.New("policyMap: Could not unmarshal inner sequence.")
			return
		}
		if len(outSeq.Bytes) == 0 { //nothing remaining to parse, stop looping after
			done = true
		}

		var oidIssue, oidSubject asn1.ObjectIdentifier
		var restIn asn1.RawContent
		restIn, err = asn1.Unmarshal(inSeq.Bytes, &oidIssue) //extract first inner CertPolicyId (issuer domain)
		if err != nil || len(restIn) == 0 {
			err = errors.New("policyMap: Could not unmarshal inner sequence.")
			return
		}

		empty, err = asn1.Unmarshal(restIn, &oidSubject) //extract second inner CertPolicyId (subject domain)
		if err != nil || len(empty) != 0 {
			err = errors.New("policyMap: Could not unmarshal inner sequence.")
			return
		}

		//append found OIDs
		out = append(out, [2]asn1.ObjectIdentifier{oidIssue, oidSubject})
	}

	return
}
func GetMappedPolicies(polMap *pkix.Extension) (out [][2]asn1.ObjectIdentifier, err error) {
	if polMap == nil {
		return nil, errors.New("policyMap: null pointer")
	}
	var outSeq, inSeq asn1.RawValue

	empty, err := asn1.Unmarshal(polMap.Value, &outSeq) //strip outer sequence tag/length should be nothing extra
	if err != nil || len(empty) != 0 || outSeq.Class != 0 || outSeq.Tag != 16 || outSeq.IsCompound == false {
		return nil, errors.New("policyMap: Could not unmarshal outer sequence.")
	}

	for done := false; !done; { //loop through SEQUENCE OF
		outSeq.Bytes, err = asn1.Unmarshal(outSeq.Bytes, &inSeq) //extract next inner SEQUENCE (OID pair)
		if err != nil || inSeq.Class != 0 || inSeq.Tag != 16 || inSeq.IsCompound == false {
			err = errors.New("policyMap: Could not unmarshal inner sequence.")
			return
		}
		if len(outSeq.Bytes) == 0 { //nothing remaining to parse, stop looping after
			done = true
		}

		var oidIssue, oidSubject asn1.ObjectIdentifier
		var restIn asn1.RawContent
		restIn, err = asn1.Unmarshal(inSeq.Bytes, &oidIssue) //extract first inner CertPolicyId (issuer domain)
		if err != nil || len(restIn) == 0 {
			err = errors.New("policyMap: Could not unmarshal inner sequence.")
			return
		}

		empty, err = asn1.Unmarshal(restIn, &oidSubject) //extract second inner CertPolicyId (subject domain)
		if err != nil || len(empty) != 0 {
			err = errors.New("policyMap: Could not unmarshal inner sequence.")
			return
		}

		//append found OIDs
		out = append(out, [2]asn1.ObjectIdentifier{oidIssue, oidSubject})
	}

	return
}
func GetMappedPolicies ( polMap * pkix . Extension ) ( out [ ] [ 2 ] asn1 . ObjectIdentifier , err error ) { if polMap == nil { return nil , errors . New ( " " ) } var outSeq , inSeq asn1 . RawValue empty , err := asn1 . Unmarshal ( polMap . Value , & outSeq ) //strip outer sequence tag/length should be nothing extra if err != nil || len ( empty ) != 0 || outSeq . Class != 0 || outSeq . Tag != 16 || outSeq . IsCompound == false { return nil , errors . New ( " " ) } for done := false ; ! done ; { //loop through SEQUENCE OF outSeq . Bytes , err = asn1 . Unmarshal ( outSeq . Bytes , & inSeq ) //extract next inner SEQUENCE (OID pair) if err != nil || inSeq . Class != 0 || inSeq . Tag != 16 || inSeq . IsCompound == false { err = errors . New ( " " ) return } if len ( outSeq . Bytes ) == 0 { //nothing remaining to parse, stop looping after done = true } var oidIssue , oidSubject asn1 . ObjectIdentifier var restIn asn1 . RawContent restIn , err = asn1 . Unmarshal ( inSeq . Bytes , & oidIssue ) //extract first inner CertPolicyId (issuer domain) if err != nil || len ( restIn ) == 0 { err = errors . New ( " " ) return } empty , err = asn1 . Unmarshal ( restIn , & oidSubject ) //extract second inner CertPolicyId (subject domain) if err != nil || len ( empty ) != 0 { err = errors . New ( " " ) return } //append found OIDs out = append ( out , [ 2 ] asn1 . ObjectIdentifier { oidIssue , oidSubject } ) } return }
//helper function to parse policyMapping extensions, returns slices of CertPolicyIds separated by domain
helper function to parse policyMapping extensions returns slices of CertPolicyIds separated by domain