user

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 13 Imported by: 4

Documentation

Overview

Package user defines user statements, store and search.

Index

Constants

This section is empty.

Variables

View Source
var ErrUserAlreadySet = errors.New("user set in sigchain already")

ErrUserAlreadySet is user already set in sigchain.

Functions

func NewSigchainStatement

func NewSigchainStatement(sc *keys.Sigchain, user *User, sk *keys.EdX25519Key, ts time.Time) (*keys.Statement, error)

NewSigchainStatement for a user to add to a Sigchain. Returns ErrUserAlreadySet is user already exists in the Sigchain.

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

Types

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

type Result

type Result struct {
	// Err if error occured.
	// See Status for type of error.
	Err string `json:"err,omitempty"`
	// Status for result. StatusOK if ok, otherwise an error type.
	Status Status `json:"status"`
	// Timestamp is the when the status was last updated.
	Timestamp int64 `json:"ts"`
	// User.
	User *User `json:"user"`
	// Statement we found at User.URL.
	Statement string `json:"statement,omitempty"`
	// Proxied if result was through a proxy.
	Proxied bool `json:"proxied,omitempty"`
	// VerifiedAt is when the status was last OK.
	VerifiedAt int64 `json:"vts,omitempty"`
}

Result describes the status of a User. TODO: Make Err/Status more explicit, it can be confusing.

func (Result) IsTimestampExpired

func (r Result) IsTimestampExpired(now time.Time, dt time.Duration) bool

IsTimestampExpired returns true if result Timestamp is older than dt.

func (Result) IsVerifyExpired

func (r Result) IsVerifyExpired(now time.Time, dt time.Duration) bool

IsVerifyExpired returns true if result VerifiedAt is older than dt.

func (Result) String

func (r Result) String() string

type Status

type Status string

Status is the status of the user statement.

const (
	// StatusOK if user was found and verified.
	StatusOK Status = "ok"
	// StatusResourceNotFound if resource (URL) was not found.
	StatusResourceNotFound Status = "resource-not-found"
	// StatusContentNotFound if resource was found, but message was missing.
	StatusContentNotFound Status = "content-not-found"
	// StatusStatementInvalid if statement was found but was invalid.
	StatusStatementInvalid Status = "statement-invalid"
	// StatusContentInvalid if statement was valid, but other data was invalid.
	StatusContentInvalid Status = "content-invalid"

	// StatusConnFailure if there was a (possibly) temporary connection failure.
	// This could be:
	// - A connection error if not connected to the internet or unable to reach the service.
	// - A 5xx error on the server.
	// - A 4xx error except 404 (for example, 429 if rate limited).
	StatusConnFailure Status = "connection-fail"

	// StatusFailure is any other failure.
	StatusFailure Status = "fail"
	// StatusUnknown is unknown.
	StatusUnknown Status = "unknown"
)

func FindVerify added in v0.1.4

func FindVerify(usr *User, b []byte, isHTML bool) (Status, string, error)

FindVerify finds and verifies content in bytes.

type User

type User struct {
	Name    string
	KID     keys.ID
	Seq     int
	Service string
	URL     string
}

User describes a name on a service with a signed statement at a URL, signed into a sigchain at (KID, seq).

func FindInSigchain

func FindInSigchain(sc *keys.Sigchain) (*User, error)

FindInSigchain returns User from a Sigchain. If user is invalid returns nil.

func New

func New(kid keys.ID, service string, name string, urs string, seq int) (*User, error)

New creates a User. Name and URL string are NOT normalized.

func NewEcho added in v0.1.5

func NewEcho(sk *keys.EdX25519Key, name string, seq int) (*User, error)

NewEcho creates a signed user@echo (for testing).

func NewForSigning

func NewForSigning(kid keys.ID, service string, name string) (*User, error)

NewForSigning returns User for signing (doesn't have remote URL yet). The name is normalized, for example for twitter "@Username" => "username".

func (User) Bytes

func (u User) Bytes() ([]byte, error)

Bytes is a serialized User.

func (User) ID

func (u User) ID() string

ID is an identifier for a user, e.g. gabriel@github.

func (User) MarshalJSON

func (u User) MarshalJSON() ([]byte, error)

MarshalJSON marshals user to JSON.

func (*User) Sign

func (u *User) Sign(key *keys.EdX25519Key) (string, error)

Sign user into an armored message.

func (User) String

func (u User) String() string

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a user from JSON.

func (*User) Validate

func (u *User) Validate() error

Validate service and name and URL. If you want to request the URL and verify the remote statement, use RequestVerify.

func (*User) Verify added in v0.1.6

func (u *User) Verify(msg string) error

Verify verifies a saltpack armored message for a user. The message should have come from the User URL and part of a verified sigchain statement with matching sequence number.

Directories

Path Synopsis
Package services defines services capable of linking a key to a user.
Package services defines services capable of linking a key to a user.

Jump to

Keyboard shortcuts

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