Skip to content

Commit

Permalink
docs: updated docs of the library (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>
  • Loading branch information
Two-Hearts committed Jul 8, 2024
1 parent d918484 commit 735fac6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# tspclient-go
Golang implementation of the Time-Stamp Protocol (TSP) client as specified in RFC3161

[![Build Status](https://github.com/notaryproject/tspclient-go/actions/workflows/build.yml/badge.svg?event=push&branch=main)](https://github.com/notaryproject/tspclient-go/actions/workflows/build.yml?query=workflow%3Abuild+event%3Apush+branch%3Amain)
[![codecov](https://codecov.io/gh/notaryproject/tspclient-go/branch/main/graph/badge.svg)](https://codecov.io/gh/notaryproject/tspclient-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/notaryproject/tspclient-go.svg)](https://pkg.go.dev/github.com/notaryproject/tspclient-go@main)

tspclient-go provides implementation of the Time-Stamp Protocol (TSP) client as specified in RFC 3161.

## Table of Contents
- [Documentation](#documentation)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

## Documentation

Library documentation is available at [Go Reference](https://pkg.go.dev/github.com/notaryproject/tspclient-go).

## Code of Conduct

This project has adopted the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).

## License

This project is covered under the Apache 2.0 license. You can read the license [here](LICENSE).
2 changes: 1 addition & 1 deletion internal/cms/cms.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Syntax (CMS) / PKCS7
//
// References:
// - RFC 5652 Cryptographic Message Syntax (CMS): https://datatracker.ietf.org/doc/html/rfc5652
// - RFC 5652 Cryptographic Message Syntax (CMS)
package cms

import (
Expand Down
6 changes: 3 additions & 3 deletions pki/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func (fi FailureInfo) Error() error {
// statusString PKIFreeText OPTIONAL,
// failInfo PKIFailureInfo OPTIONAL }
//
// PKIStatus ::= INTEGER
// PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
// PKIFailureInfo ::= BIT STRING
// PKIStatus ::= INTEGER
// PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
// PKIFailureInfo ::= BIT STRING
//
// Reference: RFC 3161 2.4.2
type StatusInfo struct {
Expand Down
14 changes: 7 additions & 7 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ func (r *Request) UnmarshalBinary(data []byte) error {

// Validate checks if req is a valid request against RFC 3161.
// It is used before a timstamp requestor sending the request to TSA.
func (req *Request) Validate() error {
if req == nil {
func (r *Request) Validate() error {
if r == nil {
return &MalformedRequestError{Msg: "request cannot be nil"}
}
if req.Version != 1 {
return &MalformedRequestError{Msg: fmt.Sprintf("request version must be 1, but got %d", req.Version)}
if r.Version != 1 {
return &MalformedRequestError{Msg: fmt.Sprintf("request version must be 1, but got %d", r.Version)}
}
hashAlg := req.MessageImprint.HashAlgorithm.Algorithm
hashAlg := r.MessageImprint.HashAlgorithm.Algorithm
hash, available := oid.ToHash(hashAlg)
if !available {
return &MalformedRequestError{Msg: fmt.Sprintf("hash algorithm %v is unavailable", hashAlg)}
}
if hash.Size() != len(req.MessageImprint.HashedMessage) {
return &MalformedRequestError{Msg: fmt.Sprintf("hashed message is of incorrect size %d", len(req.MessageImprint.HashedMessage))}
if hash.Size() != len(r.MessageImprint.HashedMessage) {
return &MalformedRequestError{Msg: fmt.Sprintf("hashed message is of incorrect size %d", len(r.MessageImprint.HashedMessage))}
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ func (r *Response) SignedToken() (*SignedToken, error) {
// Validate checks if resp is a successful timestamp response against
// its corresponding request based on RFC 3161.
// It is used when a timestamp requestor receives the response from TSA.
func (resp *Response) Validate(req *Request) error {
func (r *Response) Validate(req *Request) error {
if req == nil {
return &InvalidResponseError{Msg: "missing corresponding request"}
}
if resp == nil {
if r == nil {
return &InvalidResponseError{Msg: "response cannot be nil"}
}
if err := resp.validateStatus(); err != nil {
if err := r.validateStatus(); err != nil {
return err
}
token, err := resp.SignedToken()
token, err := r.SignedToken()
if err != nil {
return &InvalidResponseError{Detail: err}
}
Expand Down
4 changes: 1 addition & 3 deletions tspclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// limitations under the License.

// Package tspclient generates timestamping requests to TSA servers,
// fetches and verifies the responses according to
// RFC 3161: https://datatracker.ietf.org/doc/html/rfc3161 &
// RFC 5816: https://datatracker.ietf.org/doc/html/rfc5816
// fetches and verifies the responses according to RFC 3161 and RFC 5816
package tspclient

import "context"
Expand Down

0 comments on commit 735fac6

Please sign in to comment.