key

package
v0.800.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package key encodes and parses JaWS request and session keys.

This package is a textual codec only. Successful parsing does not prove that a request or session is live or authorized, nor does it enforce request single-use or client binding; package github.com/linkdata/jaws owns those checks.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(b []byte, key Key) []byte

Append appends key in the text form used by JaWS to b.

A zero Key (the invalid key) appends nothing and returns b unchanged, matching Key.String, which encodes a zero Key as the empty string.

Types

type Key

type Key uint64

Key identifies a JaWS request or session.

A zero Key is invalid and encodes as an empty string. Non-zero keys encode as base-32 text for use in JaWS URLs, HTML metadata and session cookies.

func Parse

func Parse(s string) (key Key, tail string)

Parse parses a JaWS key prefix from its text form.

If s contains a slash, tail is the slash and everything after it. The returned key is zero if the prefix before tail is not a valid base-32 key.

Decoding is case-insensitive (base-32 'A' and 'a' both decode to 10), while Key.String and Append always emit lowercase, so a parsed uppercase prefix does not re-encode to its own text.

Example

ExampleParse shows how a slash splits the key prefix from the trailing path.

package main

import (
	"fmt"

	"github.com/linkdata/jaws/lib/key"
)

func main() {
	k, tail := key.Parse("2/noscript")
	fmt.Printf("key=%v tail=%q\n", k, tail)
}
Output:
key=2 tail="/noscript"

func (Key) String

func (key Key) String() string

String returns key in the text form used by JaWS.

Example

ExampleKey_String shows that the zero (invalid) Key encodes as an empty string.

package main

import (
	"fmt"

	"github.com/linkdata/jaws/lib/key"
)

func main() {
	fmt.Printf("%q\n", key.Key(0).String())
}
Output:
""

Jump to

Keyboard shortcuts

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