lookup

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DNSLookup

func DNSLookup(domain, resolverAddr string) ([]Record, TrustLevel, []ParseFailure, error)

DNSLookup queries _age.<domain> TXT records for age key entries. resolverAddr is optional (e.g. "8.8.8.8:53"); empty means system default. It also returns any parse failures encountered, so callers can warn the user about malformed published records.

func DomainOf

func DomainOf(recipient string) string

DomainOf extracts the domain from a recipient string. "user@domain.de" → "domain.de", "domain.de" → "domain.de".

func HTTPSLookup

func HTTPSLookup(domain string, timeout time.Duration) ([]Record, []ParseFailure, error)

HTTPSLookup fetches https://<domain>/.well-known/age and parses age records. It also returns parse failures so callers can warn about malformed records.

func IsFullAddress

func IsFullAddress(recipient string) bool

IsFullAddress returns true if the recipient looks like user@domain.

func ParseRecordsAndFailures

func ParseRecordsAndFailures(body string) ([]Record, []ParseFailure)

ParseRecordsAndFailures parses multiple lines and returns both the valid records and a list of parse failures (with the raw offending line).

Types

type ParseFailure

type ParseFailure struct {
	Line string // raw input line
	Err  error
}

ParseFailure describes a record line that could not be parsed.

type Record

type Record struct {
	Match    string // bare domain or user@domain
	Delivery string // delivery mailbox (RCPT TO), empty = deliver to Match
	AgeKey   string // age public key (age1... or age1pq1...)
}

Record is a single entry from a DNS TXT or HTTPS well-known file.

func ParseRecord

func ParseRecord(line string) (Record, error)

ParseRecord parses a single semicolon-separated line into a Record. Format: match;delivery;age-key

func ParseRecords

func ParseRecords(body string) []Record

ParseRecords parses multiple lines (e.g. from a well-known file), discarding parse failures. Use ParseRecordsAndFailures when you need to surface them.

type Result

type Result struct {
	Recipient       string     `json:"recipient"`
	Found           bool       `json:"found"`
	Trust           TrustLevel `json:"trust,omitempty"`
	Keys            []string   `json:"recipients,omitempty"` // JSON field = "recipients" per §4.4
	SelectedKey     string     `json:"selected_key,omitempty"`
	SelectionReason string     `json:"selection_reason,omitempty"` // "single", "pq-preferred", "pq-unavailable"
	Delivery        string     `json:"delivery,omitempty"`
	Warnings        []string   `json:"warnings,omitempty"`
}

Result is the response returned by a lookup.

type Service

type Service struct {
	DNSResolver      string
	WellknownTimeout time.Duration
}

Service performs age key lookups via DNS and HTTPS.

func (*Service) Lookup

func (s *Service) Lookup(recipient string) (*Result, error)

Lookup resolves a recipient (user@domain or bare domain) to age keys. It tries HTTPS first (preferred, especially for PQ keys), then DNS.

type TrustLevel

type TrustLevel string

TrustLevel indicates how the key was discovered and how trustworthy that is.

const (
	TrustHTTPS  TrustLevel = "https"  // Web PKI / TLS authenticated
	TrustDNSSEC TrustLevel = "dnssec" // DNSSEC validated (AD bit)
	TrustDNS    TrustLevel = "dns"    // Plain DNS, unauthenticated
)

Jump to

Keyboard shortcuts

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