sigv4

package
v0.1.4821 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sigv4 signs a request with AWS Signature Version 4: by hand, a few dozen lines, rather than an SDK, for S3-compatible sync (davsync) and Amazon Bedrock's access keys (provider).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(s string, path bool) string

Escape is URI encoding as SigV4 has it: all but A–Z a–z 0–9 - _ . ~ as %XX, upper case, and / kept in a path.

func Hash

func Hash(b []byte) string

Hash is b's SHA-256, in hex: a payload's hash for Sign.

Types

type Signer

type Signer struct {
	ID, Secret string
	// Token is a temporary credential's session token, sent (and signed)
	// in X-Amz-Security-Token; "" for a long-term access key
	Token           string
	Region, Service string
	// Few signs host and the x-amz-* headers alone, for a request whose
	// other headers may still change after it is signed (the gateway's
	// anthropic-beta); every header is signed otherwise, as S3 wants
	Few bool
	// Twice escapes the path once more for its canonical form, as every
	// service but S3 checks it (SigV4's "each path segment URI-encoded
	// twice"); an S3 request's path is used as it is sent
	Twice bool
}

Signer is a credential and where it is used.

func (Signer) Sign

func (s Signer) Sign(req *http.Request, payload string, t time.Time)

Sign sets req's X-Amz-Date, X-Amz-Security-Token when there is a token, and Authorization, over the headers req has at this point (Few: host and x-amz-* alone) and its host. payload is the body's SHA-256, in hex (Hash); an S3 server wants it in X-Amz-Content-Sha256 too, which the caller sets.

Jump to

Keyboard shortcuts

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