Documentation
¶
Index ¶
- Constants
- Variables
- func BeAppendUint64(b []byte, v uint64) []byte
- func BePutUint64(b []byte, v uint64)
- func BeUint64(b []byte) uint64
- func CpuId(eax uint32) (eaxOut, ebx, ecx, edx uint32)
- func ExportingAVX2_32(src []byte, src2 []byte) int
- func ExportingAVX2_64(src []byte, src2 []byte) int
- func ExportingAVX2_128(src []byte, src2 []byte) int
- func ExportingAVX2_256(src []byte, src2 []byte) int
- func ExportingAVX2_512(src []byte, src2 []byte) int
- func ExportingAVX2_1024(src []byte, src2 []byte) int
- func GenerateED25519(rand io.Reader) (*PublicKeyEd, *PrivateKeyEd, error)
- func GenerateEDDSARandom(rand io.Reader) (*PrivateKeyEd, *PublicKeyEd, error)
- func GuardSlice(buf *[]byte, n int)
- func List(pkg string) []string
- func MoreStack(size uintptr)
- func NewDigest() *digest
- func NewEddsa(private *PrivateKeyEd, public *PublicKeyEd) (*_EDDSA, error)
- func Register(pkg, name string, available *bool)
- func Reset(pkg string)
- func Select(pkg, name string) bool
- func Sign(privateKey *PrivateKeyEd, message []byte, domPrefix, context string) [64]byte
- func SupportedCPU() bool
- func Verify__(publicKey *PublicKeyEd, message, sig []byte) bool
- type Algorithm
- type AlignedBuffer
- func (b *AlignedBuffer) Bytes() []byte
- func (b *AlignedBuffer) GetInput() []byte
- func (b *AlignedBuffer) GetInput32() []byte
- func (b *AlignedBuffer) GetOutput() []byte
- func (b *AlignedBuffer) GetOutput32() []byte
- func (b *AlignedBuffer) Reset()
- func (b *AlignedBuffer) Reset32_input()
- func (b *AlignedBuffer) Reset32_output()
- func (b *AlignedBuffer) Reset64_input()
- func (b *AlignedBuffer) Reset64_output()
- func (b AlignedBuffer) WriteResult() []byte
- func (b AlignedBuffer) WriteResult32() []byte
- func (b *AlignedBuffer) WriteToInput(b2 []byte)
- func (b *AlignedBuffer) WriteToInput32(b2 []byte)
- func (b *AlignedBuffer) WriteToOutput(b2 []byte)
- func (b *AlignedBuffer) WriteToOutput32(b2 []byte)
- type AmdZEN
- type Audience
- type CPU
- type Cyt
- type Feature
- type HashBorrower
- type Header
- type HeaderOption
- type Hmac
- type JWTTime
- type KeySource
- type Payload
- func (p *Payload) GetExpiration() *JWTTime
- func (p *Payload) GetIssuedAt() *time.Time
- func (p *Payload) GetIssuer() (string, error)
- func (p *Payload) GetSubject() (string, error)
- func (p *Payload) HasAudience(audience string) bool
- func (p *Payload) HasAudiences(aud []string) bool
- func (p *Payload) IsExpired(now time.Time) bool
- func (sc *Payload) IsID(id string) bool
- func (p *Payload) IsIssuer(issuer string) bool
- func (p *Payload) IsNotBefore(now time.Time) bool
- func (p *Payload) IsSubject(subject string) bool
- func (sc *Payload) IsValidExpiresAt(now time.Time) bool
- func (sc *Payload) IsValidIssuedAt(now time.Time) bool
- func (sc *Payload) IsValidNotBefore(now time.Time) bool
- func (p *Payload) MarshalJSON() ([]byte, error)
- func (p *Payload) UnmarshalJSON(b []byte) error
- type PoolChan
- type PrivateKeyEd
- type PublicKeyEd
- type Token
- func (t *Token[T]) BeforeSignature() []byte
- func (t *Token[T]) Build()
- func (t *Token[T]) Bytes() []byte
- func (t *Token[T]) Header() *Header
- func (t *Token[T]) HeaderPart() []byte
- func (t *Token[T]) PayloadPart() []byte
- func (t *Token[T]) SetToken(token []byte, sep1, sep2 int32)
- func (t *Token[T]) Signature() []byte
- func (t *Token[T]) SignedEddsa(privateKey *PrivateKeyEd, publicKey *PublicKeyEd) (string, error)
- func (t *Token[T]) SignedString(key []byte) (string, error)
- func (t *Token[T]) SigningString() []byte
- func (t *Token[T]) VerifyEddsa(public *PublicKeyEd) (bool, error)
- type Typ
Constants ¶
const ( KB = 1 << 10 // 1KB KB_32 = 32 << 10 // 32KB MB = 1 << 20 // 1MB MB_32 = 32 << 20 // 32MB GB = 1 << 30 // 1GB GB_32 = 32 << 30 // 32GB B_8 = 8 // 8B B_256 = 256 // 256B KB_8 = 8 << 10 // 8KB KB_256 = 256 << 10 // 256KB MB_8 = 8 << 20 // 8MB MAX_SIZE = GB // Maximum allowed size )
const (
INITIAL = 1
)
Domain separation prefixes used to disambiguate Ed25519/Ed25519ph/Ed25519ctx. See RFC 8032, Section 2 and Section 5.1.
Variables ¶
var ( ErrInvalid = errors.New("invalid bytes") ErrTokenIsINVALID = errors.New("token is invalid") ErrNil = errors.New("jwt key is nil") ErrSubjectNil = errors.New("subject is nil") ErrIssuerNil = errors.New("issuer is nil") ErrInvalidToken = errors.New("invalid token") ErrUnknownAlgorithm = errors.New("unknown algorithm") ErrInvalidKey = errors.New("invalid key") ErrDateInvalid = errors.New("invalid date") ErrSignatureInvalid = errors.New("invalid signature") ErrUnitializedToken = errors.New("unitialized token") ErrInvalidSignature = errors.New("invalid signature") ErrSeedNil = errors.New("seed is nil") ErrPayloadIsEmpty = errors.New("payload is empty") ErrInvalidSeed = errors.New("invalid seed") ErrInvalidKeySize = errors.New("invalid key size") ErrPointerToArray = errors.New("pointer to array") ErrCannotGetObjFromPool = errors.New("cannot get object from pool") ErrSizeNotVald = errors.New("size not valid") ErrCapNotValid = errors.New("cap not valid") ErrTokenExpired = errors.New("jwt: token is expired") ErrTokenNotYetValid = errors.New("jwt: token is not yet valid") )
Functions ¶
func BeAppendUint64 ¶
func BePutUint64 ¶
func ExportingAVX2_32 ¶
func ExportingAVX2_64 ¶
func ExportingAVX2_128 ¶
func ExportingAVX2_256 ¶
func ExportingAVX2_512 ¶
func ExportingAVX2_1024 ¶
func GenerateED25519 ¶
func GenerateED25519(rand io.Reader) (*PublicKeyEd, *PrivateKeyEd, error)
func GenerateEDDSARandom ¶
func GenerateEDDSARandom(rand io.Reader) (*PrivateKeyEd, *PublicKeyEd, error)
func GuardSlice ¶
func List ¶
List returns the names of all alternative implementations registered for the given package, whether available or not. The implicit base implementation is not included.
func NewEddsa ¶
func NewEddsa(private *PrivateKeyEd, public *PublicKeyEd) (*_EDDSA, error)
func Register ¶
Register records an alternative implementation of a cryptographic primitive. The implementation might be available or not based on CPU support. If available is false, the implementation is unavailable and can't be tested on this machine. If available is true, it can be set to false to disable the implementation. If all alternative implementations but one are disabled, the remaining one must be used (i.e. disabling one implementation must not implicitly disable any other). Each package has an implicit base implementation that is selected when all alternatives are unavailable or disabled.
func Select ¶
Select disables all implementations for the given package except the one with the given name. If name is empty, the base implementation is selected. It returns whether the selected implementation is available.
func SupportedCPU ¶
func SupportedCPU() bool
func Verify__ ¶
func Verify__(publicKey *PublicKeyEd, message, sig []byte) bool
Types ¶
type AlignedBuffer ¶
type AlignedBuffer struct {
// contains filtered or unexported fields
}
func NewAlignedBuffer ¶
func NewAlignedBuffer() *AlignedBuffer
func (*AlignedBuffer) Bytes ¶
func (b *AlignedBuffer) Bytes() []byte
func (*AlignedBuffer) GetInput ¶
func (b *AlignedBuffer) GetInput() []byte
func (*AlignedBuffer) GetInput32 ¶
func (b *AlignedBuffer) GetInput32() []byte
func (*AlignedBuffer) GetOutput ¶
func (b *AlignedBuffer) GetOutput() []byte
func (*AlignedBuffer) GetOutput32 ¶
func (b *AlignedBuffer) GetOutput32() []byte
func (*AlignedBuffer) Reset ¶
func (b *AlignedBuffer) Reset()
func (*AlignedBuffer) Reset32_input ¶
func (b *AlignedBuffer) Reset32_input()
func (*AlignedBuffer) Reset32_output ¶
func (b *AlignedBuffer) Reset32_output()
func (*AlignedBuffer) Reset64_input ¶
func (b *AlignedBuffer) Reset64_input()
func (*AlignedBuffer) Reset64_output ¶
func (b *AlignedBuffer) Reset64_output()
func (AlignedBuffer) WriteResult ¶
func (b AlignedBuffer) WriteResult() []byte
func (AlignedBuffer) WriteResult32 ¶
func (b AlignedBuffer) WriteResult32() []byte
func (*AlignedBuffer) WriteToInput ¶
func (b *AlignedBuffer) WriteToInput(b2 []byte)
func (*AlignedBuffer) WriteToInput32 ¶
func (b *AlignedBuffer) WriteToInput32(b2 []byte)
func (*AlignedBuffer) WriteToOutput ¶
func (b *AlignedBuffer) WriteToOutput(b2 []byte)
func (*AlignedBuffer) WriteToOutput32 ¶
func (b *AlignedBuffer) WriteToOutput32(b2 []byte)
type Audience ¶
type Audience struct {
// contains filtered or unexported fields
}
https://tools.ietf.org/html/rfc7519
func NewAudience ¶
func (*Audience) MarshalJSON ¶
func (*Audience) UnmarshalJSON ¶
type HashBorrower ¶
func (*HashBorrower[T]) Borrow ¶
func (h *HashBorrower[T]) Borrow() hash.Hash
func (*HashBorrower[T]) ReturnAll ¶
func (h *HashBorrower[T]) ReturnAll()
type Header ¶
type Header struct {
KeyID []byte `json:"kid,omitempty"`
ContentType Cyt `json:"cty,omitempty"`
Algorithm Algorithm `json:"alg,omitempty"`
Type Typ `json:"typ,omitempty"`
}
func (*Header) MarshalJSON ¶
func (*Header) UnmarshalJSON ¶
type HeaderOption ¶
type HeaderOption func(*Header)
func WithContentType ¶
func WithContentType(cty Cyt) HeaderOption
func WithKeyID ¶
func WithKeyID(kid []byte) HeaderOption
type JWTTime ¶
https://tools.ietf.org/html/rfc7519#section-2
func NumericDate ¶
func (*JWTTime) MarshalJSON ¶
func (*JWTTime) UnmarshalJSON ¶
type Payload ¶
type Payload struct {
JWTID string `json:"jti,omitempty"` // https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7
Issuer string `json:"iss,omitempty"`
Subject string `json:"sub,omitempty"`
Audience Audience `json:"aud,omitempty"` // aud admin
ExpirationTime *JWTTime `json:"exp,omitempty"`
NotBefore *JWTTime `json:"nbf,omitempty"`
IssuedAt *JWTTime `json:"iat,omitempty"`
}
func (*Payload) GetSubject ¶
func (*Payload) HasAudience ¶
func (*Payload) HasAudiences ¶
func (*Payload) IsNotBefore ¶
checks that the current time (now) is later than or equal to the NotBefore value
func (*Payload) IsValidExpiresAt ¶
valid if token currently not expired but it can be nil
func (*Payload) MarshalJSON ¶
func (*Payload) UnmarshalJSON ¶
type PoolChan ¶
type PoolChan[T any] struct { // contains filtered or unexported fields }
func NewPoolChan ¶
func (*PoolChan[T]) CurrentSize ¶
type PrivateKeyEd ¶
type PrivateKeyEd struct {
// contains filtered or unexported fields
}
func NewKeyFromSeed ¶
func NewKeyFromSeed(seed [32]byte) *PrivateKeyEd
func NewPrivateKey ¶
func NewPrivateKey(privBytes [64]byte) *PrivateKeyEd
func (*PrivateKeyEd) Public ¶
func (p *PrivateKeyEd) Public() *PublicKeyEd
type PublicKeyEd ¶
type PublicKeyEd struct {
// contains filtered or unexported fields
}
func NewPublicKey ¶
func NewPublicKey(pubBytes *[publicKeyLen]byte) *PublicKeyEd
type Token ¶
type Token[T any] struct { // contains filtered or unexported fields }
xxxxx.yyyyy.zzzzz
func ParseVerifySignature ¶
func (*Token[T]) BeforeSignature ¶
func (*Token[T]) HeaderPart ¶
func (*Token[T]) PayloadPart ¶
func (*Token[T]) SignedEddsa ¶
func (t *Token[T]) SignedEddsa(privateKey *PrivateKeyEd, publicKey *PublicKeyEd) (string, error)
func (*Token[T]) SigningString ¶
func (*Token[T]) VerifyEddsa ¶
func (t *Token[T]) VerifyEddsa(public *PublicKeyEd) (bool, error)