gopot

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2020 License: MIT Imports: 11 Imported by: 0

README

GoDoc Go Go Report Card

gopot

Platform of Trust utility functions for go.

Getting the library

go get -u github.com/holdatech/gopot/v2

Usage

package main

import (
	"fmt"

	"github.com/holdatech/gopot/v2"
)

func main() {
	secret := []byte("secret123")

	payload := struct {
		Hello string `json:"hello"`
	}{
		Hello: "World",
	}

	signature, err := gopot.CreateSignature(payload, secret)
	if err != nil {
		panic(err)
	}

	fmt.Println(signature)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoBody is returned when there's no body provided to the signature function
	ErrNoBody = errors.New("No body")
	// ErrInvalidSignature is returned when the signatures don't match
	ErrInvalidSignature = errors.New("Invalid signature")
	// ErrNoSecret is returned when there's no secret provided
	ErrNoSecret = errors.New("No secret provided")
	// ErrNoSignature is returned when there's no signature found in the request headers
	ErrNoSignature = errors.New("No signature provided")
)

Functions

func CreateSignature

func CreateSignature(d interface{}, secret []byte) (string, error)

CreateSignature creates a pot signature with the given secret

func JSONAddSpaces

func JSONAddSpaces(src []byte) []byte

JSONAddSpaces ands spaces after the value declarations in json

func Marshal

func Marshal(d interface{}) ([]byte, error)

Marshal marshals json with the POT separators added.

func SignatureVerifierMiddleware added in v2.1.0

func SignatureVerifierMiddleware(secret []byte) func(h http.Handler) http.Handler

SignatureVerifierMiddleware creates a middleware with the provided secret to verify the signatures in the incoming requests

func VerifySignatureFromRequest added in v2.1.0

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

VerifySignatureFromRequest can be used to verify the signature in the http request. It signs the request body and compares it to the signature provided in the header

Types

This section is empty.

Jump to

Keyboard shortcuts

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