Documentation ¶
Overview ¶
Package hash implements encoding and decoding of crypt(3) hashes.
The mapping between hashes and Go is described in the documentation for the Marshal and Unmarshal functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BigEndianEncoding = base64.NewEncoding(encoder).WithPadding(base64.NoPadding)
BigEndianEncoding is the unpadded big-endian base64 encoding, defined by the 64-character alphabet used by crypt(3).
var LittleEndianEncoding = base64le.NewEncoding(encoder).WithPadding(base64le.NoPadding)
LittleEndianEncoding is the unpadded little-endian base64 encoding, defined by the 64-character alphabet used by crypt(3).
Functions ¶
func Marshal ¶
Marshal returns the hash of the struct v.
Each exported struct field becomes a fragment of the hash, unless the field is omitted for the reason given below.
If the struct has a field named HashPrefix, Unmarshal records the hash prefix in that field (only strings are supported).
The encoding of each struct field can be customized by the format string stored under the "hash" key in the struct field's tag. The format string contains the following comma-separated list of options:
omitempty causes the field to be is omitted if the field value is empty group marks the field belonging to a param group param:x marks the field as a key-value param enc:x sets the encoding of the field (hash, base64 or none) length:x sets the length of the field value as a string inline causes the partial usage of the field up to length:x characters base:x sets the base for integer fields
As a special case, if the field tag is "-", the field is always omitted.
If an encountered value implements the encoding.TextMarshaler interface and is not a nil pointer, Marshal calls its MarshalText method.
Otherwise, Marshal can encode the following types:
- byte arrays
- byte slices
- signed or unsigned integers
- strings
Anonymous struct fields are marshaled as if their inner exported fields were fields in the outer struct, subject to the usual Go visibility rules.
Pointer values encode as the value pointed to.
Interface values encode as the value contained in the interface.
func Unmarshal ¶
Unmarshal parses the hash and stores the result in the value pointed to by v. If v is nil or not a pointer, or not a struct, Unmarshal returns an error.
Unmarshal uses the inverse of the rules that Marshal uses, allocating pointers as necessary.
To unmarshal data into a pointer, Unmarshal unmarshals data into the value pointed at by the pointer. If the pointer is nil, Unmarshal allocates a new value for it to point to
Types ¶
type InvalidUnmarshalError ¶
InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil struct pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type TagParamError ¶
TagParamError represents an error in the unmarshaling process caused by the use of field tags with conflicting parameter names.
func (*TagParamError) Error ¶
func (e *TagParamError) Error() string
type UnmarshalTypeError ¶
type UnmarshalTypeError struct { Value string // description of value - "EOF", "prefix", "group", "value" Type reflect.Type // type of Go value it could not be assigned to Offset int // error occurred after reading Offset bytes Struct string // name of the struct type containing the field Field string // the full path to the field Msg string // description of error }
UnmarshalTypeError describes a value that was not appropriate for a value of a specific Go type.
func (*UnmarshalTypeError) Error ¶
func (e *UnmarshalTypeError) Error() string
type UnsupportedTypeError ¶
type UnsupportedTypeError struct { Type reflect.Type // type of Go value could not be encoded Struct string // name of the struct type containing the field Field string // the full path to the field }
UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶
type UnsupportedValueError struct { Value reflect.Value Struct string // name of the struct type containing the field Field string // the full path to the field Str string }
UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string
Directories ¶
Path | Synopsis |
---|---|
Package base64le implements the little-endian variant of base64 encoding as specified by RFC 4648.
|
Package base64le implements the little-endian variant of base64 encoding as specified by RFC 4648. |
Package parse builds parse trees for crypt(3) hashes.
|
Package parse builds parse trees for crypt(3) hashes. |