wkd

package module
v0.0.0-...-bbe7fac Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 11 Imported by: 3

README

go-openpgp-wkd

GoDoc

A Go library for OpenPGP Web Key Directory.

License

MIT

Documentation

Overview

wkd implements OpenPGP Web Key Directory, defined in https://tools.ietf.org/html/draft-koch-openpgp-webkey-service-06

Index

Examples

Constants

View Source
const Base = "/.well-known/openpgpkey"

Base is the well-known base path for WKD.

View Source
const Version = 6

Version is the WKD protocol version.

Variables

View Source
var ErrNotFound = errors.New("wkd: not found")

ErrNotFound is returned when the directory doesn't contain a public key for the provided address.

Functions

func Discover

func Discover(addr string) ([]*openpgp.Entity, error)

Discover retrieves keys associated to an email address.

Example
pubkeys, err := wkd.Discover("me@davlgd.fr")
if err != nil {
	log.Fatal(err)
}

log.Println(pubkeys)
Output:

func HashAddress

func HashAddress(addr string) (string, error)

HashAddress returns the WKD hash for the local part of a given email address.

Types

type Dir

type Dir string

func (Dir) Add

func (dir Dir) Add(pubkeys []*openpgp.Entity) error

func (Dir) Init

func (dir Dir) Init() error

type Handler

type Handler struct {
	// Discover retrieves keys for an address. If there's no key available for
	// this address, ErrNotFound should be returned.
	Discover func(hash string) ([]*openpgp.Entity, error)
}

Handler is a HTTP WKD handler.

Example
h := wkd.Handler{
	Discover: func(hash string) ([]*openpgp.Entity, error) {
		stallmanHash, _ := wkd.HashAddress("rms@gnu.org")
		if hash != stallmanHash {
			return nil, wkd.ErrNotFound
		}
		return openpgp.ReadArmoredKeyRing(strings.NewReader(stallmanPubkey))
	},
}

http.ListenAndServe(":8080", &h)
Output:

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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