Documentation ¶
Index ¶
- Constants
- Variables
- func Parse(in []byte, txt *SecurityTxt) error
- func ValidateContactURI(in string) error
- func ValidateKeyURI(in string) error
- func ValidateRFC5646(in string) error
- func ValidateSecureURL(in string) error
- type Config
- type ContentTypeError
- type DomainBody
- type DomainClient
- type ErrorWrapper
- type Field
- type FieldError
- type HTTPError
- type ParseError
- type RedirectError
- type SecurityTxt
- type SignedMessage
- type SyntaxError
- type ValidateFunc
- type ValidationError
Constants ¶
const SECURITYTXTSPEC = "draft-foudil-securitytxt-09"
Variables ¶
var ( AcknowledgmentsError = errors.New("invalid field name 'acknowledgements', should be 'acknowledgments' as per section 3.5.1 of " + SECURITYTXTSPEC) EmptyValueError = errors.New("value cannot be empty") FieldNameError = errors.New("field-name should be printable US-ASCII except space and :, as per section 3.6.8 of RFC5322") SeparatorError = errors.New("no ':' found to separate field-name and value, as per section 3.6.8 of RFC5322") ValueError = errors.New("value should be printable US-ASCII except space, as per 'unstructured' syntax in section 3.2.5 of RFC5322") )
Errors during parsing - basic structure of security.txt is incorrect
var DefaultConfig = Config{ DialTimeout: 20 * time.Second, RequestTimeout: 10 * time.Second, TLSHandshakeTimeout: 5 * time.Second, Insecure: false, StrictRedirect: false, }
var (
MissingContactError = errors.New("Mandatory field 'Contact' not present as per section 3.5.3 of " + SECURITYTXTSPEC)
)
Validation errors
var Validators = map[string]ValidateFunc{ "secure-url": ValidateSecureURL, "contact-uri": ValidateContactURI, "key-uri": ValidateKeyURI, "rfc5646": ValidateRFC5646, }
Functions ¶
func Parse ¶
func Parse(in []byte, txt *SecurityTxt) error
Parse errors are collected in human-readable form in errors[] such that we have a full report on what's wrong with security.txt
func ValidateContactURI ¶
func ValidateKeyURI ¶
func ValidateRFC5646 ¶
func ValidateSecureURL ¶
Types ¶
type Config ¶
type ContentTypeError ¶
type ContentTypeError struct {
// contains filtered or unexported fields
}
func (ContentTypeError) Error ¶
func (e ContentTypeError) Error() string
type DomainBody ¶
type DomainBody struct {
// contains filtered or unexported fields
}
type DomainClient ¶
type DomainClient struct { *Config // contains filtered or unexported fields }
func NewDomainClient ¶
func NewDomainClient(config *Config) (*DomainClient, error)
func (*DomainClient) GetBody ¶
func (c *DomainClient) GetBody(url string) ([]byte, error)
Returning an error doesn't mean we don't have a body. If we can, we'll always read and return a body
func (*DomainClient) GetDomainBody ¶
func (c *DomainClient) GetDomainBody(domain string) *DomainBody
Iterate over valid endpoints and retrieve body
func (*DomainClient) GetSecurityTxt ¶
func (c *DomainClient) GetSecurityTxt(domain string) (*SecurityTxt, error)
type ErrorWrapper ¶
type ErrorWrapper struct {
// contains filtered or unexported fields
}
Generic error wrapper to make other error types with
func (ErrorWrapper) Error ¶
func (e ErrorWrapper) Error() string
func (ErrorWrapper) Unwrap ¶
func (e ErrorWrapper) Unwrap() error
type FieldError ¶
type FieldError struct {
// contains filtered or unexported fields
}
func NewInvalidTimeError ¶
func NewInvalidTimeError(f *Field, err error) FieldError
func NewMultipleValueError ¶
func NewMultipleValueError(f *Field) FieldError
func NewUnknownFieldError ¶
func NewUnknownFieldError(f *Field) FieldError
func (FieldError) Error ¶
func (e FieldError) Error() string
type HTTPError ¶
type HTTPError struct {
ErrorWrapper
}
func NewContentTypeError ¶
func NewHTTPError ¶
func NewRedirectError ¶
type ParseError ¶
type ParseError struct {
ErrorWrapper
}
func NewAcknowledgmentsError ¶
func NewAcknowledgmentsError() ParseError
func NewEmptyValueError ¶
func NewEmptyValueError() ParseError
func NewFieldNameError ¶
func NewFieldNameError() ParseError
func NewParseError ¶
func NewParseError(err error) ParseError
func NewSeparatorError ¶
func NewSeparatorError() ParseError
func NewValueError ¶
func NewValueError() ParseError
type RedirectError ¶
type RedirectError struct {
// contains filtered or unexported fields
}
func (RedirectError) Error ¶
func (e RedirectError) Error() string
type SecurityTxt ¶
type SecurityTxt struct { // Official fields Acknowledgments []string `format:"secure-url"` Canonical []string `format:"secure-url"` Contact []string `format:"contact-uri"` Encryption []string `format:"key-uri"` Expires time.Time Hiring []string `format:"secure-url"` Policy []string `format:"secure-url"` PreferredLanguages string `format:"rfc5646"` // Other useful fields Domain string RetrievedFrom string // contains filtered or unexported fields }
https://tools.ietf.org/html/draft-foudil-securitytxt-09#section-3.5 Note: we don't use the format tag yet.
func New ¶
func New(in []byte) (*SecurityTxt, error)
New extracts as many fields as possible and returns an error if there is a syntactical error, if the input is signed but the signature is incorrect or if the multiplicity of a field is not according to spec.
func (*SecurityTxt) AssignField ¶
func (t *SecurityTxt) AssignField(field *Field) error
func (*SecurityTxt) ParseErrors ¶
func (t *SecurityTxt) ParseErrors() []error
func (*SecurityTxt) Validate ¶
func (t *SecurityTxt) Validate() error
TODO: Deeper verification to check if everything is exactly to spec
type SignedMessage ¶
type SignedMessage struct {
// contains filtered or unexported fields
}
func NewSignedMessage ¶
func NewSignedMessage(in []byte) (*SignedMessage, error)
func (*SignedMessage) Message ¶
func (m *SignedMessage) Message() []byte
func (*SignedMessage) Signed ¶
func (m *SignedMessage) Signed() bool
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
Wrap error with some context
func (SyntaxError) Error ¶
func (e SyntaxError) Error() string
func (SyntaxError) Unwrap ¶
func (e SyntaxError) Unwrap() error
type ValidateFunc ¶
type ValidationError ¶
type ValidationError struct {
ErrorWrapper
}
func NewMissingContactError ¶
func NewMissingContactError() ValidationError
func NewValidationError ¶
func NewValidationError(err error) ValidationError