tei

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tei parses Transparency Exchange Identifiers (TEIs) as defined by the TEA discovery specification ("TEI syntax", discovery/readme.md of CycloneDX/transparency-exchange-api at the commit spec/SPEC_PIN.md names).

A TEI has the form tei://<domain-name>/<type>/<id>. Parse keeps the TEI exactly as written: it validates, but it never rewrites, decodes or normalises. Unknown but well-formed types are accepted, since the type registry is open.

The legacy form urn:tei:<type>:<domain>:<id> used by older drafts is not a TEI. Parse refuses it with ErrLegacyForm; ParseLegacyURN converts it explicitly, as a migration aid.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrSyntax                = errors.New("tei: invalid syntax")
	ErrLegacyForm            = errors.New("tei: legacy urn:tei: form; use tei://<domain>/<type>/<id> or tei.ParseLegacyURN")
	ErrLegacyTypeUnsupported = errors.New("tei: legacy type has no TEI v1.0.0 registry entry")
)

Errors returned by this package. Parse failures are *SyntaxError values that wrap ErrSyntax (or ErrLegacyForm for a urn:tei: input).

Functions

This section is empty.

Types

type SyntaxError

type SyntaxError struct {
	Rule  string
	Input string
	// contains filtered or unexported fields
}

SyntaxError reports which rule an input broke. Input is truncated to 64 bytes, so an error never repeats more of an untrusted string than that.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

func (*SyntaxError) Unwrap

func (e *SyntaxError) Unwrap() error

Unwrap returns ErrSyntax, or the more specific sentinel the error carries.

type TEI

type TEI struct {
	// contains filtered or unexported fields
}

TEI is a parsed Transparency Exchange Identifier. The zero value is not a valid TEI; obtain one from Parse, ParseLegacyURN or ParseCompat.

func Parse

func Parse(s string) (TEI, error)

Parse parses s as a TEI. The rules, in order: at most 2048 bytes of printable ASCII without spaces; the exact prefix tei://; exactly three parts (domain, type, id) and no ? or #; a DNS domain name without port, userinfo, IP literal or trailing dot; a type matching [a-z][a-z0-9]* of at most 32 characters; an id of RFC 3986 pchar characters with well-formed percent escapes and no encoded slash.

Example
package main

import (
	"fmt"
	"log"

	"github.com/oolong-project/tea-client-go/tei"
)

func main() {
	t, err := tei.Parse("tei://demo.rearmhq.com/uuid/b9f115fb-6688-4a3f-a262-3acc04e1fc9e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(t.Domain(), t.Type(), t.ID())
}
Output:
demo.rearmhq.com uuid b9f115fb-6688-4a3f-a262-3acc04e1fc9e

func ParseCompat

func ParseCompat(s string) (t TEI, legacy bool, err error)

ParseCompat accepts both forms: a tei:// TEI first, then a legacy urn:tei: string through ParseLegacyURN, reporting legacy so a caller can warn.

Example
package main

import (
	"fmt"
	"log"

	"github.com/oolong-project/tea-client-go/tei"
)

func main() {
	t, legacy, err := tei.ParseCompat("urn:tei:uuid:products.example.com:d4d9f54a-abcf-11ee-ac79-1a52914d44b1")
	if err != nil {
		log.Fatal(err)
	}
	if legacy {
		fmt.Println("warning: legacy urn:tei: form; use", t)
	}
}
Output:
warning: legacy urn:tei: form; use tei://products.example.com/uuid/d4d9f54a-abcf-11ee-ac79-1a52914d44b1

func ParseLegacyURN

func ParseLegacyURN(s string) (TEI, error)

ParseLegacyURN converts urn:tei:<type>:<domain>:<id> (the form older ReARM CLI versions accepted; <id> is everything after the domain, colons included) into tei://<domain>/<type>/<id'> and parses the result with Parse. uuid, eanupc, gtin, asin and udi ids are kept; a purl id is the raw PURL, Base64URL-encoded without padding; a hash id is <alg>:<hex> with SHA1, SHA256, SHA384 or SHA512 mapped to the checksum-type spelling. Other types (swid, gs1, ...) give ErrLegacyTypeUnsupported.

The conversion is a migration aid, not identity: the result may differ from the TEI a publisher prints, and then discovery answers OBJECT_UNKNOWN.

func (TEI) Domain

func (t TEI) Domain() string

Domain returns the domain name as written (case kept). DNS is case-insensitive, so callers building a URL lowercase it.

func (TEI) ID

func (t TEI) ID() string

ID returns the id part as written, still percent-encoded.

func (TEI) PURL

func (t TEI) PURL() (string, error)

PURL decodes the id of a purl TEI: the PURL, Base64URL-encoded without padding. It fails for any other type and for an id that does not decode.

func (TEI) String

func (t TEI) String() string

String returns the TEI exactly as it was parsed.

func (TEI) Type

func (t TEI) Type() Type

Type returns the TEI type.

type Type

type Type string

Type is the type part of a TEI. The constants are the types of the TEI registry at the pinned specification commit; other well-formed values are accepted and reported as unknown by Known.

const (
	TypeUUID   Type = "uuid"
	TypePURL   Type = "purl"
	TypeHash   Type = "hash"
	TypeEANUPC Type = "eanupc"
	TypeGTIN   Type = "gtin"
	TypeASIN   Type = "asin"
	TypeUDI    Type = "udi"
)

Registered TEI types (tei-types/ at the pinned specification commit).

func (Type) Known

func (t Type) Known() bool

Known reports whether t is one of the registered types above.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL