Skip to content

Commit

Permalink
Reverts nil handling in Key
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Nov 28, 2024
1 parent 49e1e9d commit 11d861f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
11 changes: 1 addition & 10 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,10 @@ func NewKey(namespace string, setName string, key interface{}) (*Key, Error) {
// NewKeyWithDigest initializes a key from namespace, optional set name and user key.
// The server handles record identifiers by digest only.
func NewKeyWithDigest(namespace string, setName string, key interface{}, digest []byte) (*Key, Error) {
var userKey Value = nil
if key != nil {
userKey = NewValue(key)
// make sure the key type is valid
if err := verifyKey(userKey); err != nil {
return nil, err
}
}

newKey := &Key{
namespace: namespace,
setName: setName,
userKey: userKey,
userKey: NewValue(key),
}

if err := newKey.SetDigest(digest); err != nil {
Expand Down
16 changes: 0 additions & 16 deletions key_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,3 @@ func (vb *keyWriter) writeKey(val Value) Error {
// TODO: Replace the error message with fmt.Sprintf("Key Generation Error. Value type not supported: %T", val)
return newError(types.PARAMETER_ERROR, "Key Generation Error. Value not supported: "+val.String())
}

func verifyKey(val Value) Error {
switch val.(type) {
case IntegerValue:
return nil
case LongValue:
return nil
case StringValue:
return nil
case BytesValue:
return nil
}

// TODO: Replace the error message with fmt.Sprintf("Key Generation Error. Value type not supported: %T", val)
return newError(types.PARAMETER_ERROR, "Key Generation Error. Value not supported: "+val.String())
}
5 changes: 1 addition & 4 deletions key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ var _ = gg.Describe("Key Test", func() {
gm.Expect(err, nil)
gm.Expect(key.Digest()).To(gm.Equal([]byte("01234567890123456789")))

key, err = as.NewKeyWithDigest("namespace", "set", []interface{}{}, []byte("01234567890123456789"))
gm.Expect(err).To(gm.HaveOccurred())

key, err = as.NewKeyWithDigest("namespace", "set", nil, []byte("01234567890123456789"))
key, _ = as.NewKeyWithDigest("namespace", "set", []interface{}{}, []byte("01234567890123456789"))
gm.Expect(key.Digest()).To(gm.Equal([]byte("01234567890123456789")))
})

Expand Down

0 comments on commit 11d861f

Please sign in to comment.