signature

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package signature verify request for any AWS service.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TimeNow is a variable that holds the function to get the current time
	TimeNow = time.Now
)

Functions

func EncodeAPIErrorToResponse

func EncodeAPIErrorToResponse(err APIError) []byte

EncodeAPIErrorToResponse encodes APIerror to http response

func EncodeResponse

func EncodeResponse(response interface{}) []byte

EncodeResponse encodes the response headers into XML format.

func ReloadKeys

func ReloadKeys(pairs map[string]string)

func StoreKeys

func StoreKeys(pairs map[string]string)

LoadKeys parse and store accessKey-secretKey pair

Types

type APIError

type APIError struct {
	Code           string
	Description    string
	HTTPStatusCode int
}

APIError is API Error structure

func GetAPIError

func GetAPIError(errCode ErrorCode) APIError

GetAPIError decodes Signerror[int] to APIerror[encodable]

type Credentials

type Credentials struct {
	AccessKey    string                 `xml:"AccessKeyId" json:"accessKey,omitempty"`
	SecretKey    string                 `xml:"SecretAccessKey" json:"secretKey,omitempty"`
	Expiration   time.Time              `xml:"Expiration" json:"expiration,omitempty"`
	SessionToken string                 `xml:"SessionToken" json:"sessionToken,omitempty"`
	Status       string                 `xml:"-" json:"status,omitempty"`
	ParentUser   string                 `xml:"-" json:"parentUser,omitempty"`
	Groups       []string               `xml:"-" json:"groups,omitempty"`
	Claims       map[string]interface{} `xml:"-" json:"claims,omitempty"`
}

Credentials holds access and secret keys.

type CredentialsV2 added in v0.0.5

type CredentialsV2 struct {
	AccessKey string
	SecretKey string
}

CredentialsV2 - for signature-V2 calculation

func (CredentialsV2) SignV2 added in v0.0.5

func (c CredentialsV2) SignV2(method string,
	encodedResource string,
	encodedQuery string,
	headers http.Header,
	expires string) string

Sign - return the Authorization header value.

type ErrorCode

type ErrorCode int

ErrorCode is code[int] of APIError

const (
	ErrUnsupportAlgorithm ErrorCode

	// ErrNone is None(err=nil)
	ErrNone
)

func ParseSignV2 added in v0.0.5

func ParseSignV2(v2Auth string) (sv signV2Values, err ErrorCode)

Parses signature version '2' header of the following form.

Authorization: AWS NXM00iAJpLvPYC94VRDd:q20e3MP/dZOpnzBZTvo619ONSpU=

func ParseSignV4

func ParseSignV4(v4Auth string) (sv signValues, err ErrorCode)

Parses signature version '4' header of the following form.

Authorization: algorithm Credential=accessKeyID/credScope,  SignedHeaders=signedHeaders, Signature=signature

func V2SignVerify added in v0.0.5

func V2SignVerify(r *http.Request) ErrorCode

func V4SignVerify

func V4SignVerify(r *http.Request) ErrorCode

V4SignVerify - Verify authorization header with calculated header in accordance with

returns nil if signature matches.

Jump to

Keyboard shortcuts

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