Skip to content

Commit

Permalink
Refactor comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullHypothesis committed Oct 14, 2024
1 parent e60a930 commit b5d944c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 6 additions & 2 deletions internal/nonce/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ import (
"github.com/Amnesic-Systems/veil/internal/errs"
)

const Len = 20 // The length of a nonce in bytes.
// Len is the length of a nonce in bytes.
const Len = 20

var (
// Accessing rand.Reader via variable facilitates mocking.
cryptoRead = rand.Reader
errNotEnoughRead = errors.New("failed to read enough random bytes")
)

// Nonce is a random value that guarantees attestation document freshness.
type Nonce [Len]byte

// URLEncode returns the nonce as a URL-encoded string.
func (n *Nonce) URLEncode() string {
return url.QueryEscape(
base64.StdEncoding.EncodeToString(n[:]),
)
}

// New creates a new nonce.
func New() (*Nonce, error) {
// TODO: panic on error cause we may not be able to recover?
var newNonce Nonce
n, err := cryptoRead.Read(newNonce[:])
if err != nil {
Expand All @@ -38,6 +41,7 @@ func New() (*Nonce, error) {
return &newNonce, nil
}

// FromSlice turns a byte slice into a nonce.
func FromSlice(s []byte) (*Nonce, error) {
if len(s) != Len {
return nil, errs.InvalidLength
Expand Down
2 changes: 0 additions & 2 deletions internal/service/attestation/aux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package attestation

// TODO: does this belong in the enclave package?

import (
"slices"

Expand Down
2 changes: 0 additions & 2 deletions internal/service/attestation/hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
// the enclave's attestation document for clients to verify.
type Hashes struct {
sync.Mutex
// TODO: is this better off in models? model.AttestationHashes sounds less
// nice though
TlsKeyHash [sha256.Size]byte `json:"tls_key_hash"` // Always set.
AppKeyHash [sha256.Size]byte `json:"app_key_hash"` // Only set if the application has keys.
}
Expand Down

0 comments on commit b5d944c

Please sign in to comment.