/* Package inspect describes RSA-related objects such as private keys and X.509 certificates using structured, annotated key-value pairs. */ package inspect // Type of item. type Type int const ( TypePrivateKey Type = iota TypePublicKey TypeX509Certificate TypeX509CRL TypeX509CSR TypeTLSConnectionState ) func (t Type) String() string { switch t { case TypePrivateKey: return "RSA private key" case TypePublicKey: return "RSA public key" case TypeX509Certificate: return "X.509 certificate" case TypeX509CRL: return "certificate revocation list" case TypeX509CSR: return "certificate signing request" case TypeTLSConnectionState: return "TLS connection state" default: return "???" } } // Info about an item. type Info interface { // Type of item. Type() Type // Location where the item was encountered (e.g. line number for a file, // or position in certificate chain for TLS handshake. Location() string // Info returns a structured set of information about the item. Info() []Section } // Section is a set of related fields. type Section struct { // Title of section. Title string // Fields contain a related set of key, value pairs. Fields []Field } // Field is an aspect of information about an item. type Field struct { // Key is the name of the aspect. Key string // Value is its value. Value any } // BadInfo is an item which cannot be parsed, e.g. an invalid DER-encoded item // within a PEM block. It implements both error and Info. type BadInfo struct { Typ Type Loc string Underlying error } // Type reports the type of item that was being parsed. func (b *BadInfo) Type() Type { return b.Typ } // Location reports further information about the location of the item. func (b *BadInfo) Location() string { return b.Loc } // Info reports an "Error encountered" section with an "Error" field. func (b *BadInfo) Info() []Section { return []Section{ Section{ Title: "Error encountered", Fields: []Field{ Field{ Key: "Error", Value: b.Underlying, }, }, }, } } // Error returns the underlying error string. func (b *BadInfo) Error() string { return b.Underlying.Error() } // Unwrap returns the underlying error. func (b *BadInfo) Unwrap() error { return b.Underlying }