Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Documentation #294

Merged
merged 30 commits into from
Mar 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
33cd35d
docs: module, client, clientconfig Go documentation
wobondar Mar 13, 2024
44393ef
docs: types documentation
wobondar Mar 14, 2024
797b2c0
docs: format package documentation, minor fixes
wobondar Mar 14, 2024
7e7c73e
docs: SDK model package documentation
wobondar Mar 14, 2024
006146b
refactor(suite): get rid of a global variable
wobondar Mar 14, 2024
3e51706
refactor(suite): move MessageType to format package
wobondar Mar 14, 2024
fd76e8b
refactor(suite): move ContentAADString into bodyaad package
wobondar Mar 14, 2024
de1b7bc
docs: suite package documentation
wobondar Mar 14, 2024
a349dfa
refactor(utils): move rand under internal package
wobondar Mar 15, 2024
c1de113
refactor(providers): move providers common package under internal pac…
wobondar Mar 15, 2024
d86de45
refactor(utils): move itertools package under internal package
wobondar Mar 15, 2024
15d68d4
docs: providers package documentation
wobondar Mar 15, 2024
c019d35
docs: arn package documentation
wobondar Mar 15, 2024
50b6d41
refactor(utils): move arn package
wobondar Mar 15, 2024
ba880e3
fix(utils): lint issues with arn pkg
wobondar Mar 15, 2024
1626bb1
refactor(utils): move structs package, documentation
wobondar Mar 15, 2024
eb7fc1a
docs: materials package documentation
wobondar Mar 15, 2024
ef714bb
refactor(utils): conv package moved under internal packages, document…
wobondar Mar 15, 2024
87c67b2
refactor(utils): keyderivation moved under internal packages, documen…
wobondar Mar 15, 2024
977473a
refactor(utils): move GCM encryption under internal packages, documen…
wobondar Mar 15, 2024
7e53348
docs(model): GCM encryption documentation
wobondar Mar 15, 2024
2f13e36
docs(keys): KMS key documentation
wobondar Mar 15, 2024
7be11ab
docs(keys): Raw Master Key documentation
wobondar Mar 15, 2024
14c34b2
docs(keys): Base key and generic key errors documentation
wobondar Mar 15, 2024
0db7e4b
docs(kmsprovider): KMS Master Key Provider documentation
wobondar Mar 15, 2024
550b27b
chore(model): Custom key provider type
wobondar Mar 21, 2024
b7f04d2
feat(keyprovider): keyprovider alias package
wobondar Mar 21, 2024
e0b2c89
fix(kmsprovider): clean up
wobondar Mar 21, 2024
092d82e
docs(rawprovider): Raw Master Key Provider documentation
wobondar Mar 21, 2024
22d9a34
docs: update README
wobondar Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: format package documentation, minor fixes
wobondar committed Mar 14, 2024

Verified

This commit was signed with the committer’s verified signature.
wobondar Andrew
commit 797b2c09fd971a6efd6b4974acd3bd736f4cd016

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/internal/crypto/decrypter/decrypt.go
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ func (d *Decrypter) decryptData(ctx context.Context, ciphertext []byte) ([]byte,
}

if d.verifier != nil {
footer, errFooter := d.deser.DeserializeFooter(d.header.AlgorithmSuite(), buf)
footer, errFooter := d.deser.DeserializeFooter(buf, d.header.AlgorithmSuite())
if errFooter != nil {
return nil, nil, errFooter
}
6 changes: 3 additions & 3 deletions pkg/internal/serialization/deserializer.go
Original file line number Diff line number Diff line change
@@ -34,10 +34,10 @@ func (d *Deserializer) DeserializeHeader(buf *bytes.Buffer, maxEDK int) (format.
return header, authData, nil
}

func (d *Deserializer) DeserializeBody(buf *bytes.Buffer, algorithm *suite.AlgorithmSuite, frameLen int) (format.MessageBody, error) {
return deserializeBody(algorithm, frameLen, buf)
func (d *Deserializer) DeserializeBody(buf *bytes.Buffer, alg *suite.AlgorithmSuite, frameLen int) (format.MessageBody, error) {
return deserializeBody(alg, frameLen, buf)
}

func (d *Deserializer) DeserializeFooter(alg *suite.AlgorithmSuite, buf *bytes.Buffer) (format.MessageFooter, error) {
func (d *Deserializer) DeserializeFooter(buf *bytes.Buffer, alg *suite.AlgorithmSuite) (format.MessageFooter, error) {
return deserializeFooter(alg, buf)
}
8 changes: 4 additions & 4 deletions pkg/internal/serialization/deserializer_test.go
Original file line number Diff line number Diff line change
@@ -202,8 +202,8 @@ func TestDeserializer_DeserializeBody(t *testing.T) {

func TestDeserializer_DeserializeFooter(t *testing.T) {
type args struct {
alg *suite.AlgorithmSuite
buf *bytes.Buffer
alg *suite.AlgorithmSuite
}
tests := []struct {
name string
@@ -214,17 +214,17 @@ func TestDeserializer_DeserializeFooter(t *testing.T) {
{
name: "Nil Buffer",
args: args{
alg: suite.AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384,
buf: nil,
alg: suite.AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384,
},
want: nil,
wantErr: true,
},
{
name: "Valid Footer Deserialize",
args: args{
alg: suite.AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384,
buf: bytes.NewBuffer(concatSlices([]byte{0x0, 0x67}, make([]byte, 103))),
alg: suite.AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384,
},
want: &footer{
algorithmSuite: suite.AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384,
@@ -237,7 +237,7 @@ func TestDeserializer_DeserializeFooter(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &Deserializer{}
got, err := d.DeserializeFooter(tt.args.alg, tt.args.buf)
got, err := d.DeserializeFooter(tt.args.buf, tt.args.alg)
if tt.wantErr {
assert.Error(t, err)
assert.Nil(t, got)
16 changes: 16 additions & 0 deletions pkg/model/format/body.go
Original file line number Diff line number Diff line change
@@ -3,17 +3,33 @@

package format

// BodyFrame contains information about the body frame.
type BodyFrame interface {
Serializable

// IsFinal indicates true if the frame is final.
IsFinal() bool

// SequenceNumber returns the frame sequence number.
SequenceNumber() int

// IV returns the frame IV.
IV() []byte

// EncryptedContent returns the frame encrypted content.
EncryptedContent() []byte

// AuthenticationTag returns the frame authentication tag.
AuthenticationTag() []byte
}

// MessageBody contains information about the message body.
type MessageBody interface {
Serializable

// Frames returns the body frames.
Frames() []BodyFrame

// AddFrame adds new BodyFrame to the body.
AddFrame(final bool, seqNum int, IV []byte, contentLength int, ciphertext, authTag []byte) error
}
5 changes: 5 additions & 0 deletions pkg/model/format/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright Chainify Group LTD. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package format provides set of interfaces for SDK message format.
package format
5 changes: 5 additions & 0 deletions pkg/model/format/footer.go
Original file line number Diff line number Diff line change
@@ -3,8 +3,13 @@

package format

// MessageFooter contains information about the message footer.
type MessageFooter interface {
Serializable

// SignLen returns the length of the signature.
SignLen() int

// Signature returns the signature.
Signature() []byte
}
60 changes: 53 additions & 7 deletions pkg/model/format/header.go
Original file line number Diff line number Diff line change
@@ -7,50 +7,96 @@ import (
"github.com/chainifynet/aws-encryption-sdk-go/pkg/suite"
)

// Serializable is an interface for objects that can be serialized to bytes.
type Serializable interface {
// Len returns the length of the serialized object.
Len() int
// Bytes returns the serialized object.
Bytes() []byte
}

type messageHeaderBase interface {
// MessageHeaderBase is the common interface for the message header.
type MessageHeaderBase interface {
// Version returns the message format version.
Version() suite.MessageFormatVersion

// AlgorithmSuite returns the algorithm suite used with the message.
AlgorithmSuite() *suite.AlgorithmSuite

// MessageID returns the message ID.
MessageID() []byte

// AADLength returns the length of the additional authenticated data.
AADLength() int

// AADData returns the additional authenticated data.
AADData() MessageAAD

// EncryptedDataKeyCount returns the number of encrypted data keys.
EncryptedDataKeyCount() int

// EncryptedDataKeys returns the encrypted data keys.
EncryptedDataKeys() []MessageEDK

// ContentType returns the content type.
ContentType() suite.ContentType

// FrameLength returns the frame length.
FrameLength() int
}

// MessageHeader contains information about the message header.
type MessageHeader interface {
Serializable
messageHeaderBase
Type() suite.MessageType // present only in V1
Reserved() []byte // present only in V1
IVLength() int // present only in V1
AlgorithmSuiteData() []byte // present only in V2
MessageHeaderBase

// Type returns the message type. Present only in V1.
Type() suite.MessageType

// Reserved returns the reserved bytes. Present only in V1.
Reserved() []byte

// IVLength returns the length of the IV. Present only in V1.
IVLength() int

// AlgorithmSuiteData returns the algorithm suite data. Present only in V2.
AlgorithmSuiteData() []byte
}

// MessageEDK contains information about the encrypted data key.
type MessageEDK interface {
Serializable

// ProviderID returns the provider ID.
ProviderID() string

// ProviderInfo returns the provider info.
ProviderInfo() string

// EncryptedDataKey returns the encrypted data key.
EncryptedDataKey() []byte
}

// MessageAAD contains information about the additional authenticated data.
type MessageAAD interface {
Serializable

// EncryptionContext returns the encryption context.
EncryptionContext() suite.EncryptionContext
}

// MessageHeaderAuth contains information about the message header authentication.
type MessageHeaderAuth interface {
Serializable

// AuthData returns the authentication data.
AuthData() []byte
IV() []byte // present only in V1

// IV returns the IV. Present only in V1.
IV() []byte
}

// HeaderParams contains the parameters to be used to create [MessageHeader].
type HeaderParams struct {
AlgorithmSuite *suite.AlgorithmSuite
MessageID []byte
31 changes: 29 additions & 2 deletions pkg/model/format/serialization.go
Original file line number Diff line number Diff line change
@@ -9,15 +9,42 @@ import (
"github.com/chainifynet/aws-encryption-sdk-go/pkg/suite"
)

// Deserializer defines methods for deserializing encrypted message components.
type Deserializer interface {
// DeserializeHeader deserializes a message header from a buffer.
// It takes a buffer and a maximum number of encrypted data keys as input.
// It returns a MessageHeader, MessageHeaderAuth, and an error if any.
DeserializeHeader(buf *bytes.Buffer, maxEncryptedDataKeys int) (MessageHeader, MessageHeaderAuth, error)
DeserializeBody(buf *bytes.Buffer, algorithm *suite.AlgorithmSuite, frameLen int) (MessageBody, error)
DeserializeFooter(alg *suite.AlgorithmSuite, buf *bytes.Buffer) (MessageFooter, error)

// DeserializeBody deserializes a message body from a buffer.
// It takes a buffer, an algorithm suite, and a frame length as input.
// It returns a MessageBody and an error if any.
DeserializeBody(buf *bytes.Buffer, alg *suite.AlgorithmSuite, frameLen int) (MessageBody, error)

// DeserializeFooter deserializes a message footer from a buffer.
// It takes a buffer and an algorithm suite as input.
// It returns a MessageFooter and an error if any.
DeserializeFooter(buf *bytes.Buffer, alg *suite.AlgorithmSuite) (MessageFooter, error)
}

// Serializer defines methods for serializing encrypted message components.
type Serializer interface {
// SerializeHeader serializes a message header.
// It takes header parameters as input and returns a MessageHeader and an error if any.
SerializeHeader(p HeaderParams) (MessageHeader, error)

// SerializeHeaderAuth serializes a message header authentication data.
// It takes a message format version, an initialization vector, and authentication data as input.
// It returns a MessageHeaderAuth and an error if any.
SerializeHeaderAuth(v suite.MessageFormatVersion, iv, authData []byte) (MessageHeaderAuth, error)

// SerializeBody serializes a message body.
// It takes an algorithm suite and a frame length as input.
// It returns a MessageBody and an error if any.
SerializeBody(alg *suite.AlgorithmSuite, frameLength int) (MessageBody, error)

// SerializeFooter serializes a message footer.
// It takes an algorithm suite and a signature as input.
// It returns a MessageFooter and an error if any.
SerializeFooter(alg *suite.AlgorithmSuite, signature []byte) (MessageFooter, error)
}