sig

package module
v2.0.0-...-d5ea2bc Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DigestHeaderKey       = http.CanonicalHeaderKey("Digest")
	DigestHeaderSHAPrefix = "sha-256="
	ContentMD5HeaderKey   = http.CanonicalHeaderKey("Content-MD5")
	ExpiresHeaderKey      = http.CanonicalHeaderKey("Expires")
	DateHeaderKey         = http.CanonicalHeaderKey("Date")
	ContentTypeHeaderKey  = http.CanonicalHeaderKey("Content-Type")
	KeyIDHeaderKey        = http.CanonicalHeaderKey("X-Nl-Key-Id")
)
View Source
var (
	ErrorEmptyHost                = errors.New("empty host value")
	ErrorMissingMD5Header         = errors.New("missing 'Content-MD5' header in requests")
	ErrorMissingContentTypeHeader = errors.New("missing 'Content-Type' header in requests")
	ErrorIncorrectMD5Header       = errors.New("incorrect 'Content-MD5' header in requests")
	ErrorMissingDateHeader        = errors.New("missing 'Date' header in requests")
	ErrorMissingExpiresHeader     = errors.New("missing 'Expires' header in requests")
	ErrorMissingDigestHeader      = errors.New("missing 'Digest' header in requests")
	ErrorIncorrectDigestHeader    = errors.New("incorrect 'Digest' header in requests")
	ErrorIncorrectExpireHeader    = errors.New("incorrect 'Expires' header in requests")
	ErrorExpiredRequest           = errors.New("the request is expired")
	ErrorSignatureMismatch        = errors.New("request signature mismatch")
)

Functions

func AddHeadersAndSignRequest

func AddHeadersAndSignRequest(r *http.Request, secret []byte, bodyMD5 string) error

func GetBodyMD5

func GetBodyMD5(r *http.Request) string

func GetMD5

func GetMD5(data []byte) string

func Sign

func Sign(s string, key []byte) string

SignString sing the string -> base64 -> url encode

func SignRequest

func SignRequest(r *http.Request, secret []byte, bodyMD5 string) error

func SignString

func SignString(s string, key []byte) string

SignString sing the string -> base64 -> url encode

func VerifySignature

func VerifySignature(r *http.Request, secret []byte) error

VerifySignature Check the signature from request, if signature is valid, not error returns

Signature = URL-Encode( Base64( HMAC-SHA1( YourSecretAccessKey, UTF-8-Encoding-Of( StringToSign ) ) ) ); StringToSign = HTTP-VERB + "\n" +

Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
Expires+ "\n" +
HTTP-HOST

func SignRequest(r *http.Request, secret, body []byte) (*http.Request, error) {
	if len(r.Host) == 0 {
		return r, ErrorEmptyHost
	}
}

Types

type SigningData

type SigningData struct {
	Method      string
	BodyMD5     string
	ContentType string
	Date        string
	Expires     int64
	Host        string
}

func (SigningData) String

func (sd SigningData) String() string

Jump to

Keyboard shortcuts

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