This is an automated email from the ASF dual-hosted git repository.

rxl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e55be0  Fix minor api issue and comments. (#637)
4e55be0 is described below

commit 4e55be0a363ef57e90a60a29803b578d0498c1d1
Author: cckellogg <[email protected]>
AuthorDate: Wed Oct 13 02:39:15 2021 -0400

    Fix minor api issue and comments. (#637)
    
    Fix some comment spelling mistakes and spelling on one api.
---
 pulsar/crypto/crypto_failure_action.go  |  2 +-
 pulsar/crypto/default_message_crypto.go | 12 ++++++------
 pulsar/crypto/encryption_key_Info.go    |  8 ++++----
 pulsar/crypto/message_crypto.go         | 12 ++++++++----
 pulsar/crypto/message_metadata.go       | 12 ++++++------
 pulsar/crypto/message_metadata_test.go  |  6 +++---
 6 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/pulsar/crypto/crypto_failure_action.go 
b/pulsar/crypto/crypto_failure_action.go
index 891d740..0bdd289 100644
--- a/pulsar/crypto/crypto_failure_action.go
+++ b/pulsar/crypto/crypto_failure_action.go
@@ -21,7 +21,7 @@ const (
        // ProducerCryptoFailureActionFail this is the default option to fail 
send if crypto operation fails.
        ProducerCryptoFailureActionFail = iota
 
-       // ProducerCryptoFailureActionSend ingnore crypto failure and proceed 
with sending unencrypted message.
+       // ProducerCryptoFailureActionSend ignore crypto failure and proceed 
with sending unencrypted message.
        ProducerCryptoFailureActionSend
 )
 
diff --git a/pulsar/crypto/default_message_crypto.go 
b/pulsar/crypto/default_message_crypto.go
index 93a0244..74e4592 100644
--- a/pulsar/crypto/default_message_crypto.go
+++ b/pulsar/crypto/default_message_crypto.go
@@ -34,7 +34,7 @@ import (
        "github.com/apache/pulsar-client-go/pulsar/log"
 )
 
-// DefaultMessageCrypto implmentation of the interface MessageCryto
+// DefaultMessageCrypto implementation of the interface MessageCryto
 type DefaultMessageCrypto struct {
        // data key which is used to encrypt/decrypt messages
        dataKey []byte
@@ -134,7 +134,7 @@ func (d *DefaultMessageCrypto) RemoveKeyCipher(keyName 
string) bool {
        return true
 }
 
-// Encrypt encrypt payload using encryption keys and add encrypted data key
+// Encrypt payload using encryption keys and add encrypted data key
 // to message metadata. Here data key is encrypted
 // using public key
 func (d *DefaultMessageCrypto) Encrypt(encKeys []string,
@@ -161,7 +161,7 @@ func (d *DefaultMessageCrypto) Encrypt(encKeys []string,
                        keyInfo, keyInfoOk := k.(*EncryptionKeyInfo)
 
                        if keyInfoOk {
-                               msgMetadata.UpsertEncryptionkey(*keyInfo)
+                               msgMetadata.UpsertEncryptionKey(*keyInfo)
                        } else {
                                d.logger.Error("failed to get EncryptionKeyInfo 
for key %v", keyName)
                        }
@@ -206,8 +206,8 @@ func (d *DefaultMessageCrypto) Encrypt(encKeys []string,
        return gcm.Seal(nil, nonce, payload, nil), nil
 }
 
-// Decrypt decrypt the payload using decrypted data key.
-// Here data key is read from from the message
+// Decrypt the payload using decrypted data key.
+// Here data key is read from the message
 // metadata and  decrypted using private key.
 func (d *DefaultMessageCrypto) Decrypt(msgMetadata MessageMetadataSupplier,
        payload []byte,
@@ -285,7 +285,7 @@ func (d *DefaultMessageCrypto) 
getKeyAndDecryptData(msgMetadata MessageMetadataS
                                return decryptedData, nil
                        }
                } else {
-                       // First time, entry wont be present in cache
+                       // First time, entry won't be present in cache
                        d.logger.Debugf("%s Failed to decrypt data or data key 
is not in cache. Will attempt to refresh", d.logCtx)
                }
        }
diff --git a/pulsar/crypto/encryption_key_Info.go 
b/pulsar/crypto/encryption_key_Info.go
index 8418682..11dd444 100644
--- a/pulsar/crypto/encryption_key_Info.go
+++ b/pulsar/crypto/encryption_key_Info.go
@@ -24,7 +24,7 @@ type EncryptionKeyInfo struct {
        name     string
 }
 
-// NewEncryptionKeyInfo
+// NewEncryptionKeyInfo create a new EncryptionKeyInfo
 func NewEncryptionKeyInfo(name string, key []byte, metadata map[string]string) 
*EncryptionKeyInfo {
        return &EncryptionKeyInfo{
                metadata: metadata,
@@ -33,17 +33,17 @@ func NewEncryptionKeyInfo(name string, key []byte, metadata 
map[string]string) *
        }
 }
 
-// GetKey get key
+// Name get the name of the key
 func (eci *EncryptionKeyInfo) Name() string {
        return eci.name
 }
 
-// GetValue get value
+// Key get the key data
 func (eci *EncryptionKeyInfo) Key() []byte {
        return eci.key
 }
 
-// GetMetadata get key metadata
+// Metadata get key metadata
 func (eci *EncryptionKeyInfo) Metadata() map[string]string {
        return eci.metadata
 }
diff --git a/pulsar/crypto/message_crypto.go b/pulsar/crypto/message_crypto.go
index 4ad1eec..4a17b71 100644
--- a/pulsar/crypto/message_crypto.go
+++ b/pulsar/crypto/message_crypto.go
@@ -19,17 +19,21 @@ package crypto
 
 // MessageCrypto implement this interface to encrypt and decrypt messages
 type MessageCrypto interface {
-       // AddPublicKeyCipher
+
+       // AddPublicKeyCipher encrypt data using the public key(s) in the 
argument.
+       // If more than one key name is specified, data key is encrypted using 
each of those keys.
+       // If the public key is expired or changed, application is responsible 
to remove
+       // the old key and add the new key.
        AddPublicKeyCipher(keyNames []string, keyReader KeyReader) error
 
-       // RemoveKeyCipher remove the key indentified by the keyname from the 
list
+       // RemoveKeyCipher remove the key from the list
        RemoveKeyCipher(keyName string) bool
 
        // Encrypt the payload using the data key and update
-       // message metadata with the keyname and encrypted data key
+       // message metadata with the key and encrypted data key
        Encrypt(encKeys []string, KeyReader KeyReader, msgMetadata 
MessageMetadataSupplier, payload []byte) ([]byte, error)
 
        // Decrypt the payload using the data key.
-       // Keys used to ecnrypt the data key can be retrieved from msgMetadata
+       // Keys used to encrypt the data key can be retrieved from msgMetadata
        Decrypt(msgMetadata MessageMetadataSupplier, payload []byte, KeyReader 
KeyReader) ([]byte, error)
 }
diff --git a/pulsar/crypto/message_metadata.go 
b/pulsar/crypto/message_metadata.go
index 042a6a0..717b0c0 100644
--- a/pulsar/crypto/message_metadata.go
+++ b/pulsar/crypto/message_metadata.go
@@ -23,13 +23,13 @@ import (
 
 // MessageMetadataSupplier wrapper implementation around message metadata
 type MessageMetadataSupplier interface {
-       // GetEncryptionKeys read all the encryption keys from the 
MessageMetadata
+       // EncryptionKeys read all the encryption keys from the MessageMetadata
        EncryptionKeys() []EncryptionKeyInfo
 
-       // UpsertEncryptionkey add new or update existing EncryptionKeys in to 
the MessageMetadata
-       UpsertEncryptionkey(EncryptionKeyInfo)
+       // UpsertEncryptionKey add new or update existing EncryptionKeys in to 
the MessageMetadata
+       UpsertEncryptionKey(EncryptionKeyInfo)
 
-       // GetEncryptionParam read the ecryption parameter from the 
MessageMetadata
+       // EncryptionParam read the ecryption parameter from the MessageMetadata
        EncryptionParam() []byte
 
        // SetEncryptionParam set encryption parameter in to the MessageMetadata
@@ -58,7 +58,7 @@ func (m *MessageMetadata) EncryptionKeys() 
[]EncryptionKeyInfo {
        return nil
 }
 
-func (m *MessageMetadata) UpsertEncryptionkey(keyInfo EncryptionKeyInfo) {
+func (m *MessageMetadata) UpsertEncryptionKey(keyInfo EncryptionKeyInfo) {
        if m.messageMetadata != nil {
                idx := m.encryptionKeyPresent(keyInfo)
                newKey := &pb.EncryptionKeys{
@@ -101,7 +101,7 @@ func (m *MessageMetadata) encryptionKeyPresent(keyInfo 
EncryptionKeyInfo) int {
 
 func getKeyMeta(metaMap map[string]string) []*pb.KeyValue {
        if len(metaMap) > 0 {
-               meta := []*pb.KeyValue{}
+               var meta []*pb.KeyValue
                for k, v := range metaMap {
                        meta = append(meta, &pb.KeyValue{Key: &k, Value: &v})
                }
diff --git a/pulsar/crypto/message_metadata_test.go 
b/pulsar/crypto/message_metadata_test.go
index 3e8cb38..c55cd24 100644
--- a/pulsar/crypto/message_metadata_test.go
+++ b/pulsar/crypto/message_metadata_test.go
@@ -24,7 +24,7 @@ import (
        "github.com/stretchr/testify/assert"
 )
 
-func TestGetEncyptionKeys(t *testing.T) {
+func TestGetEncryptionKeys(t *testing.T) {
        msgMetadata := &pb.MessageMetadata{}
        name1 := "key-1"
        value1 := []byte{1, 2, 3, 4}
@@ -95,10 +95,10 @@ func TestUpsertEncryptionKey(t *testing.T) {
 
        msgMetadataSupplier := NewMessageMetadataSupplier(msgMetadata)
 
-       msgMetadataSupplier.UpsertEncryptionkey(*keyInfo)
+       msgMetadataSupplier.UpsertEncryptionKey(*keyInfo)
 
        // try to add same key again
-       msgMetadataSupplier.UpsertEncryptionkey(*keyInfo)
+       msgMetadataSupplier.UpsertEncryptionKey(*keyInfo)
 
        actual := msgMetadataSupplier.EncryptionKeys()
 

Reply via email to