Skip to content

Commit

Permalink
fix:add binary interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mertakman committed Jan 9, 2025
1 parent 0e4a51c commit 20fc256
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cng/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package cng
import (
"bytes"
"crypto"
"errors"
"hash"
"runtime"
"unsafe"
Expand Down Expand Up @@ -250,6 +251,18 @@ func (h *hashX) BlockSize() int {
return int(h.alg.blockSize)
}

func (hx *hashX) MarshalBinary() ([]byte, error) {
return nil, errors.New("cng: hash state is not marshallable")
}

func (hx *hashX) AppendBinary(b []byte) ([]byte, error) {
return nil, errors.New("cng: hash state is not marshallable")
}

func (hx *hashX) UnmarshalBinary(data []byte) error {
return errors.New("cng: hash state is not marshallable")
}

// hashData writes p to ctx. It panics on error.
func hashData(ctx bcrypt.HASH_HANDLE, p []byte) {
var n int
Expand Down
25 changes: 25 additions & 0 deletions cng/sha3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package cng

import (
"errors"
"hash"
"runtime"
"unsafe"
Expand Down Expand Up @@ -164,6 +165,18 @@ func (h *DigestSHA3) BlockSize() int {
return int(h.alg.blockSize)
}

func (ds *DigestSHA3) MarshalBinary() ([]byte, error) {
return nil, errors.New("cng: hash state is not marshallable")
}

func (ds *DigestSHA3) AppendBinary(b []byte) ([]byte, error) {
return nil, errors.New("cng: hash state is not marshallable")
}

func (ds *DigestSHA3) UnmarshalBinary(data []byte) error {
return errors.New("cng: hash state is not marshallable")
}

// NewSHA3_256 returns a new SHA256 hash.
func NewSHA3_256() *DigestSHA3 {
return newDigestSHA3(bcrypt.SHA3_256_ALGORITHM)
Expand Down Expand Up @@ -284,3 +297,15 @@ func (s *SHAKE) Reset() {
func (s *SHAKE) BlockSize() int {
return int(s.blockSize)
}

func (s *SHAKE) MarshalBinary() ([]byte, error) {
return nil, errors.New("cng: hash state is not marshallable")
}

func (s *SHAKE) AppendBinary(b []byte) ([]byte, error) {
return nil, errors.New("cng: hash state is not marshallable")
}

func (s *SHAKE) UnmarshalBinary(data []byte) error {
return errors.New("cng: hash state is not marshallable")
}

0 comments on commit 20fc256

Please sign in to comment.