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 ¶
- Variables
- func Bool(v bool) *bool
- func CheckResponse(r *http.Response) error
- func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)
- func DoRequestWithClient(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)
- func Int(v int) *int
- func MarshalURLQuery(v interface{}) (queries url.Values)
- func NewHTTPClientWithCertificate(certPath, keyPath string, options ...bool) (*http.Client, error)
- func StreamToString(stream io.Reader) string
- func String(v string) *string
- type CertificateResponse
- type Client
- func (c *Client) AuthToken() string
- func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)
- func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)
- func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)
- func (c *Client) SetAuthToken(token string)
- type ClientOpt
- type DSSIdentity
- type DigitalSigningService
- type ErrorResponse
- type ExpiredIdentityFunc
- type IdentityRequest
- type IdentityResponse
- type IdentityVault
- type ListRequest
- type ListResult
- type LoginRequest
- type LoginResponse
- type LoginService
- type Manager
- func (s *Manager) GetIdentity(ctx context.Context, signer string, req *IdentityRequest) (*DSSIdentity, error)
- func (s *Manager) Sign(ctx context.Context, signer string, identityReq *IdentityRequest, ...) ([]byte, error)
- func (s *Manager) Timestamp(ctx context.Context, signer string, identityReq *IdentityRequest, ...) ([]byte, error)
- type ManagerOption
- type RequestCompletionCallback
- type Response
- type SigningRequest
- type SigningResponse
- type TimestampRequest
- type TimestampResponse
- type TrustChainResponse
- type URLQueryEncoder
- type ValidationError
- type VaultItem
Constants ¶
This section is empty.
Variables ¶
var (
ErrDigestRequired = errors.New("file digest required")
)
errors definition
Functions ¶
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func CheckResponse ¶
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 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 ¶
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 ¶
MarshalURLQuery encode struct into url queries using `json` tag as query name reference
func NewHTTPClientWithCertificate ¶
NewHTTPClientWithCertificate .
func StreamToString ¶
StreamToString converts a reader to a string
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 (*Client) Do ¶
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 ¶
SetAuthToken set authorization token which used request authorization
type ClientOpt ¶
ClientOpt are options for New.
func SetBaseURL ¶
SetBaseURL is a client option for setting the base URL.
func SetUserAgent ¶
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 ¶
type DigitalSigningService interface { Identity(context.Context, *IdentityRequest) (*IdentityResponse, *Response, error) Timestamp(context.Context, *TimestampRequest) (*TimestampResponse, *Response, error) Sign(context.Context, *SigningRequest) (*SigningResponse, *Response, error) CertificatePath(context.Context) (*CertificateResponse, *Response, error) TrustChain(context.Context) (*TrustChainResponse, *Response, error) }
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 ¶
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 ¶
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 .
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 ¶
RequestCompletionCallback defines the type of the request callback function
type 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 ¶
ValidationError contains field to field validation error message
func (ValidationError) Error ¶
func (e ValidationError) Error() string