lic

package
v0.0.0-...-7025c6a Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentType_LCP_JSON         = "application/vnd.readium.lcp.license.v1.0+json"
	ContentType_LSD_JSON         = "application/vnd.readium.license.status.v1.0+json"
	ContentType_TEXT_HTML        = "text/html"
	ContentType_JSON             = "application/json"
	ContentType_FORM_URL_ENCODED = "application/x-www-form-urlencoded"
)
View Source
const (
	LCP_Basic_Profile = "http://readium.org/lcp/basic-profile"
	LCP_10_Profile    = "http://readium.org/lcp/profile-1.0"
)
View Source
const SHA256_URI string = "http://www.w3.org/2001/04/xmlenc#sha256"

Variables

View Source
var (
	ErrLicenseNotFound = errors.New("license not found or failed to get license info")
)
View Source
var LCP_PRODUCTION_LIB = false

Functions

func GenerateUserKey

func GenerateUserKey(profile, passhash string) ([]byte, error)

GenerateUserKey function prepares the user key

Types

type ContentKey

type ContentKey struct {
	Algorithm string `json:"algorithm,omitempty"`
	Value     []byte `json:"encrypted_value,omitempty"`
}

type DeviceInfo

type DeviceInfo struct {
	ID   string
	Name string
}

StatusDoc data model

type Encryption

type Encryption struct {
	Profile    string     `json:"profile,omitempty"`
	ContentKey ContentKey `json:"content_key,omitempty"` // Not used for license generation
	UserKey    UserKey    `json:"user_key"`
}

type License

type License struct {
	Provider   string          `json:"provider"`
	UUID       string          `json:"id"`
	Issued     time.Time       `json:"issued"`
	Updated    *time.Time      `json:"updated,omitempty"`
	Encryption Encryption      `json:"encryption"`
	Links      []Link          `json:"links,omitempty"`
	User       UserInfo        `json:"user"`
	Rights     UserRights      `json:"rights"`
	Signature  *sign.Signature `json:"signature,omitempty"`
}

func NewLicense

func NewLicense(config *conf.Config, cert *tls.Certificate, pubInfo *stor.Publication, licInfo *stor.LicenseInfo, userInfo *UserInfo, encryption *Encryption, passhash string) (*License, error)

NewLicense generates a license from db info, request data and config data

func (*License) CheckSignature

func (license *License) CheckSignature() error

CheckSignature verifies the signature of a license

type LicenseCtrl

type LicenseCtrl struct {
	*conf.Config // TODO: change for an interface (dependency)
	stor.Store
}

StatusDoc data model

func NewLicenseCtrl

func NewLicenseCtrl(cf *conf.Config, st stor.Store) *LicenseCtrl

func (*LicenseCtrl) NewStatusDoc

func (lc *LicenseCtrl) NewStatusDoc(license *stor.LicenseInfo) *StatusDoc

NewStatusDoc returns a Status Document

func (*LicenseCtrl) Register

func (lc *LicenseCtrl) Register(licenseID string, device *DeviceInfo) (*StatusDoc, error)

Register records that a new device is using a license

func (*LicenseCtrl) Renew

func (lc *LicenseCtrl) Renew(licenseID string, device *DeviceInfo, newEnd *time.Time) (*StatusDoc, error)

Renew extends the end date of a license

func (*LicenseCtrl) Return

func (lc *LicenseCtrl) Return(licenseID string, device *DeviceInfo) (*StatusDoc, error)

Return forces the expiration of a license and returns a status document.

func (*LicenseCtrl) Revoke

func (lc *LicenseCtrl) Revoke(licenseID string) (*StatusDoc, error)

Revoke forces the expiration of a license and returns a status document.

type LicenseManager

type LicenseManager interface {
	Register(license *stor.LicenseInfo) error
	Renew(license *stor.LicenseInfo) error
	Return(license *stor.LicenseInfo) error
	Revoke(license *stor.LicenseInfo) error
}

License management interface

type Link struct {
	Rel       string `json:"rel"`
	Href      string `json:"href"`
	Type      string `json:"type,omitempty"`
	Title     string `json:"title,omitempty"`
	Profile   string `json:"profile,omitempty"`
	Templated bool   `json:"templated,omitempty"`
	Size      int64  `json:"length,omitempty"`
	Checksum  string `json:"hash,omitempty"`
}

type PotentialRights

type PotentialRights struct {
	End *time.Time `json:"end,omitempty"`
}

StatusDoc data model

type StatusDoc

type StatusDoc struct {
	ID              string           `json:"id"`
	Status          string           `json:"status"`
	Message         string           `json:"message"`
	Updated         Updated          `json:"updated"`
	Links           []Link           `json:"links"`
	PotentialRights *PotentialRights `json:"potential_rights,omitempty"`
	Events          []stor.Event     `json:"events,omitempty"`
}

StatusDoc data model

type Updated

type Updated struct {
	License time.Time `json:"license"`
	Status  time.Time `json:"status"`
}

StatusDoc data model

type UserInfo

type UserInfo struct {
	ID        string   `json:"id"`
	Email     string   `json:"email,omitempty"`
	Name      string   `json:"name,omitempty"`
	Encrypted []string `json:"encrypted,omitempty"`
}

type UserKey

type UserKey struct {
	Algorithm string `json:"algorithm,omitempty"` // Not used for license generation
	TextHint  string `json:"text_hint,omitempty"`
	Keycheck  []byte `json:"key_check,omitempty"` // Not used for license generation
}

type UserRights

type UserRights struct {
	Start *time.Time `json:"start,omitempty"`
	End   *time.Time `json:"end,omitempty"`
	Print *int32     `json:"print,omitempty"`
	Copy  *int32     `json:"copy,omitempty"`
}

Jump to

Keyboard shortcuts

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