ghtoken

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ghtoken provides features for working with GitHub tokens.

Index

Constants

View Source
const (
	// Base62Alphabet "enum" to choose a specific base62 alphabet while
	// encoding/decoding; more often than not, due to the alphabet that
	// Golang's big.Int package uses, an inverted alphabet should be chosen
	// when working with tokens produced by or intended to be consumed by
	// GitHub.
	Base62Alphabet = true

	// PrefixLength "enum" so we're not using magic numbers; prefixes of
	// GitHub tokens are 3 characters long.
	PrefixLength = 3
	// ChecksumLength "enum" so we're not using magic numbers; after the
	// checksum is calculated, it occupies the last 6 characters in the final
	// GitHub token.
	ChecksumLength = 6
	// PayloadLength "enum" so we're not using magic numbers; once the
	// prefix and '_' are stripped from a GitHub token, the resulting payload
	// is 36 characters long.
	PayloadLength = 36
	// InputLength "enum" so we're not using magic numbers; token input is
	// the token payload without the appended checksum.
	InputLength = PayloadLength - ChecksumLength
	// Sep is the character that separates a GitHub token's prefix from
	// it's payload.
	Sep = "_"
)

Variables

This section is empty.

Functions

func GetValidPrefixes

func GetValidPrefixes() []string

GetValidPrefixes returns a string slice of the valid GitHub token prefixes.

func IsValidPrefix

func IsValidPrefix(prefix string) bool

IsValidPrefix returns if the given string is a valid ghToken prefix.

Types

type GhToken

type GhToken struct {
	FullToken      string `json:"fullToken"`
	Prefix         string `json:"prefix"`
	EncodedPayload string `json:"encodedPayload"`
	EncodedInput   string `json:"encodedInput"`
	EncodedCrc     string `json:"encodedCrc"`
	SchemaChecked  bool   `json:"schemaChecked"`
	SchemaValid    bool   `json:"schemaValid"`
}

GhToken holds full token and pre-carved components of a GitHub token.

func ParseGhToken

func ParseGhToken(tok string) *GhToken

ParseGhToken builds a new ghToken struct from a GitHub token string; if token is malformed, a ghToken struct is returned that only has FullToken populated (based on the original input).

func (GhToken) HasValidChecksum

func (token GhToken) HasValidChecksum() bool

HasValidChecksum a GitHub token's checksum.

func (GhToken) HasValidPrefix

func (token GhToken) HasValidPrefix() bool

HasValidPrefix returns whether or not the token's prefix is valid.

func (GhToken) PrintTokenAttributes

func (token GhToken) PrintTokenAttributes()

PrintTokenAttributes prints the ghToken struct, and simply logs an error if it fails to pretty print.

func (*GhToken) ValidateSchema

func (token *GhToken) ValidateSchema()

ValidateSchema checks the token's prefix and checksum; once a token's schema is validated, flags are set in the GhToken to signify that it has been checked and whether or not it appears to have a valid schema.

Jump to

Keyboard shortcuts

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