crypto

package
v0.21.4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: BSD-2-Clause Imports: 9 Imported by: 1

Documentation

Overview

Package crypto contains common cryptographic elements.

Index

Constants

View Source
const (
	SHA1        = Hash(crypto.SHA1)        // import crypto/sha1
	SHA224      = Hash(crypto.SHA224)      // import crypto/sha256
	SHA256      = Hash(crypto.SHA256)      // import crypto/sha256
	SHA384      = Hash(crypto.SHA384)      // import crypto/sha512
	SHA512      = Hash(crypto.SHA512)      // import crypto/sha512
	SHA3_256    = Hash(crypto.SHA3_256)    // import golang.org/x/crypto/sha3
	SHA3_512    = Hash(crypto.SHA3_512)    // import golang.org/x/crypto/sha3
	BLAKE2b_256 = Hash(crypto.BLAKE2b_256) // import golang.org/x/crypto/blake2b
	BLAKE2b_512 = Hash(crypto.BLAKE2b_512) // import golang.org/x/crypto/blake2b
)

A list of commonly supported hashes and the imports required to enable them.

View Source
const NS = "urn:xmpp:hashes:2"

NS is the namespace used by this package.

Variables

View Source
var (
	ErrMissingAlgo  = errors.New("crypto: no algo attr found")
	ErrUnknownAlgo  = errors.New("crypto: unknown hash value")
	ErrUnlinkedAlgo = errors.New("crypto: attempted to use a hash function without an implementation linked in")
)

A list of errors returned by functions in this package. Error checking against these errors should always use errors.Is and not a direct comparison.

View Source
var (
	Feature = info.Feature{Var: NS}
)

A list of service discovery features that are supported by this package.

Functions

func Features

func Features(h ...Hash) info.FeatureIter

Features returns an iter that can be registered against a mux to advertise support for the hash list. The iter will return an error for any hashes that are not available in the binary.

Types

type Hash

type Hash crypto.Hash

Hash identifies a cryptographic hash function that is implemented in another package. It is like crypto/hash from the standard library, except only hash functions commonly supported in XMPP are given names and values have methods that are useful for communicating information about supported hashes over the wire.

func Parse

func Parse(name string) (Hash, error)

Parse creates a hash from the hash name as a string.

func (Hash) Available

func (h Hash) Available() bool

Available reports whether the given hash function is linked into the binary.

func (Hash) HashFunc

func (h Hash) HashFunc() crypto.Hash

HashFunc returns the hash as a crypto.Hash and implements crypto.SignerOpts.

func (Hash) MarshalXML

func (h Hash) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.Marshaler. MarshalXML panics if the hash is invalid.

func (Hash) MarshalXMLAttr

func (h Hash) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr implements xml.MarshalerAttr.

func (Hash) Namespace

func (h Hash) Namespace() (string, error)

Namespace returns a unique URN for the hash algorithm. If the hash algorithm is unknown, Namespace returns an error.

func (Hash) New

func (h Hash) New() hash.Hash

New returns a new hash.Hash calculating the given hash function. New panics if the hash is invalid.

func (Hash) Size

func (h Hash) Size() int

Size returns the length, in bytes, of a digest resulting from the given hash function. It doesn't require that the hash function in question be linked into the program.

func (Hash) String

func (h Hash) String() string

String implements fmt.Stringer by returning the name of the hash as it would appear in wire format. This is different from the value returned by the String method of crypto.Hash.

func (Hash) TokenReader

func (h Hash) TokenReader() xml.TokenReader

TokenReader implements xmlstream.Marshaler. TokenReader panics if the hash is invalid.

func (*Hash) UnmarshalXML

func (h *Hash) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler.

func (*Hash) UnmarshalXMLAttr

func (h *Hash) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr implements xml.UnmarshalerAttr.

func (Hash) WriteXML

func (h Hash) WriteXML(w xmlstream.TokenWriter) (int, error)

WriteXML implements xmlstream.WriterTo. WriteXML panics if the hash is invalid.

type HashOutput

type HashOutput struct {
	Hash Hash
	Out  []byte
}

HashOutput is used to marshal or unmarshal the results of a hash calculation.

func (HashOutput) MarshalXML

func (h HashOutput) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.Marshaler.

func (HashOutput) TokenReader

func (h HashOutput) TokenReader() xml.TokenReader

TokenReader implements xmlstream.Marshaler. TokenReader panics if the original hash is invalid.

func (*HashOutput) UnmarshalXML

func (h *HashOutput) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler.

func (HashOutput) WriteXML

func (h HashOutput) WriteXML(w xmlstream.TokenWriter) (int, error)

WriteXML implements xmlstream.WriterTo.

Jump to

Keyboard shortcuts

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