INNER CODE UNIT · Go

findTLVTag

go-piv/piv-go · v2/piv/key.go:813

func findTLVTag(data []byte, targetTag uint32) ([]byte, error) {
	// Manually parse tags and lengths using cryptobyte primitives instead of
	// cryptobyte's ReadASN1 methods because:
	// 1. cryptobyte does not support high-tag-number format (tags > 30), which
	//    are used in PIV.
	// 2. cryptobyte enforces strict DER, whereas PIV may use BER (non-minimal
	//    length encoding).
	s := cryptobyte.String(data)
	for !s.Empty() {
		var tagByte byte
		if !s.ReadUint8(&tagByte) {
			return nil, errMalformedTLV
		}
		tag := uint32(tagByte)
		// Handle multi-byte tags: if the lowest 5 bits are 11111,
		// the tag is multi-byte.
		if tagByte&0x1F == 0x1F {
			lastByteFound := false

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…