Documentation ¶
Index ¶
- Variables
- func AddHeadersAndSignRequest(r *http.Request, secret []byte, bodyMD5 string) error
- func GetBodyMD5(r *http.Request) string
- func GetMD5(data []byte) string
- func Sign(s string, key []byte) string
- func SignRequest(r *http.Request, secret []byte, bodyMD5 string) error
- func SignString(s string, key []byte) string
- func VerifySignature(r *http.Request, secret []byte) error
- type SigningData
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 GetBodyMD5 ¶
func SignString ¶
SignString sing the string -> base64 -> url encode
func VerifySignature ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.