{"modulePath":"github.com/foxcpp/go-mtasts","version":"v0.0.0-20261026071820-d380f1fa8aa1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package mtasts\n\nThe mtasts policy implements parsing, caching and checking of MTA-STS (RFC 8461) policies.\n\n## Variables\n\n```go\nvar ErrNoPolicy = errors.New(\"mtasts: no policy\")\n```\nErrNoPolicy indicates that remote domain does not offer a MTA-STS policy or it was ignored due to errors.\n\nCallers should not check for this directly and use IsNoPolicy function to decide actual handling strategy.\n\n## Functions\n\n```go\nfunc IsNoPolicy(err error) bool\n```\n\n## Types\n\n```go\ntype Cache struct {\n\tStore    Store\n\tResolver Resolver\n\n\t// If non-nil replaces the function used to download policy texts.\n\tDownloadPolicy func(domain string) (*Policy, error)\n}\n```\nCache structure implements transparent MTA-STS policy caching using provided Store implementation.\n\nIt is the only way to fetch policies as caching is important to prevent downgrade attacks.\n\ngoroutine-safety is solely defined by safety of the underlying Store and Resolver objects.\n\n```go\nfunc NewFSCache(directory string) *Cache\n```\nNewFSCache creates the Cache object using FS directory to store cached policies.\n\nThe specified directory should exist and be writtable.\n\n```go\nfunc NewNopCache() *Cache\n```\nNewNopCache creates the Cache object that never stores fetched policies and always repeats the lookup.\n\nIt should be used only for tests, caching is criticial for the MTA-STS security model.\n\n```go\nfunc NewRAMCache() *Cache\n```\nNewRAMCache creates the Cache object using RAM map to store cached policies.\n\nThe underlying Store implementation is goroutine-safe.\n\n```go\nfunc (c *Cache) Get(ctx context.Context, domain string) (*Policy, error)\n```\nGet reads policy from cache or tries to fetch it from Policy Host.\n\nThe domain is assumed to be normalized, as done by dns.ForLookup.\n\n```go\nfunc (c *Cache) Refresh() error\n```\n\n```go\ntype MalformedDNSRecordError struct {\n\t// Additional description of the error.\n\tDesc string\n}\n```\n\n```go\nfunc (e MalformedDNSRecordError) Error() string\n```\n\n```go\ntype MalformedPolicyError struct {\n\t// Additional description of the error.\n\tDesc string\n}\n```\n\n```go\nfunc (e MalformedPolicyError) Error() string\n```\n\n```go\ntype Mode string\n```\n\n```go\nconst (\n\tModeEnforce Mode = \"enforce\"\n\tModeTesting Mode = \"testing\"\n\tModeNone    Mode = \"none\"\n)\n```\n\n```go\ntype Policy struct {\n\tMode   Mode\n\tMaxAge int\n\tMX     []string\n}\n```\n\n```go\nfunc (p Policy) Match(mx string) bool\n```\n\n```go\ntype Resolver interface {\n\tLookupTXT(ctx context.Context, domain string) ([]string, error)\n}\n```\n\n```go\ntype Store interface {\n\t// List method is used by Cache.Refresh to clean policy data.\n\tList() ([]string, error)\n\n\t// Store method is used by Cache to store policy data.\n\tStore(key string, id string, fetchTime time.Time, policy *Policy) error\n\n\t// Load method is used by Cache to load policy data previously stored\n\t// using Store.\n\t//\n\t// If there is no cached policy, Load should return ErrNoPolicy.\n\tLoad(key string) (id string, fetchTime time.Time, policy *Policy, err error)\n}\n```\n\n","path":"github.com/foxcpp/go-mtasts","name":"mtasts","synopsis":"The mtasts policy implements parsing, caching and checking of MTA-STS (RFC 8461) policies.","isRedistributable":true}
