Skip to content

Commit

Permalink
Added comment on MarshalJSON to explain the reason of the intermediat…
Browse files Browse the repository at this point in the history
…e struct
  • Loading branch information
daeMOn63 committed Aug 13, 2019
1 parent 60e19f8 commit 6c3b34e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions keys/publickey.go
Expand Up @@ -239,6 +239,8 @@ func (k *pubKeyMaterial) SetKey(key []byte) error {
// MarshalJSON will infer the key type in the marshalled json data
// to be able to know which key to instantiate when unmarshalling back
func (k *pubKeyMaterial) MarshalJSON() ([]byte, error) {
// we have to use a temporary intermediate struct here as
// passing directly k to KeyData would cause an infinite loop of MarshalJSON calls
jsonKey := &jsonKey{
KeyType: pubKeyMaterialType,
KeyData: struct {
Expand Down
2 changes: 2 additions & 0 deletions keys/symmetric.go
Expand Up @@ -83,6 +83,8 @@ func (k *symKeyMaterial) SetKey(key []byte) error {
// MarshalJSON will infer the key type in the marshalled json data
// to be able to know which key to instantiate when unmarshalling back
func (k *symKeyMaterial) MarshalJSON() ([]byte, error) {
// we have to use a temporary intermediate struct here as
// passing directly k to KeyData would cause an infinite loop of MarshalJSON calls
jsonKey := &jsonKey{
KeyType: symKeyMaterialType,
KeyData: struct {
Expand Down

0 comments on commit 6c3b34e

Please sign in to comment.