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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Domain returns the domain name as written (case kept). DNS is case-insensitive, so callers building a URL lowercase it.
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.