globalsign

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 17 Imported by: 0

README

Globalsign DSS client SDK

a client SDK for communicatiing with globalsign DSS (digital signing service)

for unidoc integration see integration package

...

// create globalsign manager
manager, err := globalsign.NewManager(&globalsign.ManagerOption{
	APIKey:             "<API KEY>",
	APISecret:          "<API SECRET>",
	BaseURL:            "<BASE_URL>",
	PrivateKeyPath:     "<KEY_PATH>",
	TLSCertificatePath: "<CERT_PATH>",
})
if err != nil {
	return err
}

// Create signature handler.
handler, err := integration.NewGlobalSignDSS(context.Background(), manager, option.SignedBy, map[string]interface{}{
	"common_name": "Galih Rivanto"
})
if err != nil {
	return err
}

// Create signature.
signature := model.NewPdfSignature(handler) 
...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDigestRequired = errors.New("file digest required")
)

errors definition

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

DoRequest submits an HTTP request.

func DoRequestWithClient

func DoRequestWithClient(
	ctx context.Context,
	client *http.Client,
	req *http.Request) (*http.Response, error)

DoRequestWithClient submits an HTTP request using the specified client.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.

func MarshalURLQuery

func MarshalURLQuery(v interface{}) (queries url.Values)

MarshalURLQuery encode struct into url queries using `json` tag as query name reference

func NewHTTPClientWithCertificate

func NewHTTPClientWithCertificate(certPath, keyPath string, options ...bool) (*http.Client, error)

NewHTTPClientWithCertificate .

func StreamToString

func StreamToString(stream io.Reader) string

StreamToString converts a reader to a string

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type CertificateResponse

type CertificateResponse struct {
	CA string `json:"path"`
}

CertificateResponse .

type Client

type Client struct {
	sync.Mutex

	// login / authentication service
	LoginService LoginService

	// digital signing service (dss)
	DigitalSigningService DigitalSigningService
	// contains filtered or unexported fields
}

Client manage communication with wdms ap

func New

func New(httpClient *http.Client, opts ...ClientOpt) (*Client, error)

New returns a new Globalsign API client instance.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new API client.

func (*Client) AuthToken

func (c *Client) AuthToken() string

AuthToken get authorization token which used request authorization

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the DO API request completion callback

func (*Client) SetAuthToken

func (c *Client) SetAuthToken(token string)

SetAuthToken set authorization token which used request authorization

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

SetUserAgent is a client option for setting the user agent.

type DSSIdentity

type DSSIdentity struct {
	// Identity
	ID string

	SigningCert string

	OCSP string

	CA string

	Ts time.Time
}

DSSIdentity represent acquired credential from login and identity request

type DigitalSigningService

DigitalSigningService .

type ErrorResponse

type ErrorResponse struct {
	// original response
	Response *http.Response

	// Error code
	Code int `json:"code"`

	// Description of error
	Message string `json:"detail"`
}

ErrorResponse wrap standard http Response along with error code and message which returned from wdms api

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ExpiredIdentityFunc

type ExpiredIdentityFunc func(key string, identity *DSSIdentity)

ExpiredIdentityFunc is a callback which will be called once identity expired

type IdentityRequest

type IdentityRequest struct {
	SubjectDn map[string]interface{} `json:"subject_dn"`
}

IdentityRequest .

type IdentityResponse

type IdentityResponse struct {
	ID           string `json:"id"`
	SigningCert  string `json:"signing_cert"`
	OCSPResponse string `json:"ocsp_response"`
}

IdentityResponse .

type IdentityVault

type IdentityVault struct {
	// contains filtered or unexported fields
}

IdentityVault store DSS identity until its expired

func NewIdentityVault

func NewIdentityVault(duration time.Duration) *IdentityVault

NewIdentityVault is a helper to create instance of the indetities vault struct

func (*IdentityVault) Count

func (cache *IdentityVault) Count() int

Count returns the number of items in the cache (helpful for tracking memory leaks)

func (*IdentityVault) Del

func (cache *IdentityVault) Del(key string)

Del remove item without trigger callback

func (*IdentityVault) Get

func (cache *IdentityVault) Get(key string) (data *DSSIdentity, found bool)

Get is a thread-safe way to lookup items

func (*IdentityVault) Set

func (cache *IdentityVault) Set(key string, identity *DSSIdentity)

Set is a thread-safe way to add identity to cache

type ListRequest

type ListRequest struct {
	Page int `json:"page,omitempty"`

	// Number of results to return per page.
	Limit int `json:"limit,omitempty"`

	// search	A search term.
	Search string `json:"search,omitempty"`

	// ordering
	Ordering int `json:"ordering,omitempty"`
}

ListRequest contains common parameter for list request

type ListResult

type ListResult struct {
	Count int `json:"count"`

	// next page link
	Next     string `json:"next"`
	Previous string `json:"previous"`
}

ListResult contains common field from api result

type LoginRequest

type LoginRequest struct {
	APIKey    string `json:"api_key"`
	APISecret string `json:"api_secret"`
}

LoginRequest .

type LoginResponse

type LoginResponse struct {
	AccessToken string `json:"access_token"`
}

LoginResponse .

type LoginService

type LoginService interface {
	Login(context.Context, *LoginRequest) (*LoginResponse, *Response, error)
}

LoginService .

type Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager .

func NewManager

func NewManager(option *ManagerOption) (*Manager, error)

NewManager is a wrapper for client and

func (*Manager) GetIdentity

func (s *Manager) GetIdentity(ctx context.Context, signer string, req *IdentityRequest) (*DSSIdentity, error)

GetIdentity .

func (*Manager) Sign

func (s *Manager) Sign(ctx context.Context, signer string, identityReq *IdentityRequest, digest []byte) ([]byte, error)

Sign .

func (*Manager) Timestamp

func (s *Manager) Timestamp(ctx context.Context, signer string, identityReq *IdentityRequest, digest []byte) ([]byte, error)

Timestamp .

type ManagerOption

type ManagerOption struct {
	BaseURL            string
	APIKey             string
	APISecret          string
	TLSCertificatePath string
	PrivateKeyPath     string
	InsecureSkipVerify bool
}

ManagerOption .

func (*ManagerOption) Valid

func (o *ManagerOption) Valid() bool

Valid determine whether option is valid

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

type Response

type Response struct {
	*http.Response
}

Response wraps standard http Response with default response fields which returned from wdms api

type SigningRequest

type SigningRequest struct {
	ID string `json:"id"`

	// a hex encoded sha256 checksum for source file
	Digest string `json:"digest"`
}

SigningRequest .

type SigningResponse

type SigningResponse struct {
	Signature string `json:"signature"`
}

SigningResponse .

type TimestampRequest

type TimestampRequest struct {
	Digest string `json:"digest"`
}

TimestampRequest .

type TimestampResponse

type TimestampResponse struct {
	Token string `json:"token"`
}

TimestampResponse .

type TrustChainResponse

type TrustChainResponse struct {
	Path string `json:"path"`
}

TrusChainResponse .

type URLQueryEncoder

type URLQueryEncoder interface {
	MarshalURLQuery() string
}

URLQueryEncoder .

type ValidationError

type ValidationError map[string]string

ValidationError contains field to field validation error message

func (ValidationError) Error

func (e ValidationError) Error() string

type VaultItem

type VaultItem struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

VaultItem represents a record identity

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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