Skip to content

Commit

Permalink
fix: improve some error messages (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: tenkoh <[email protected]>
  • Loading branch information
tenkoh and tenkoh authored Sep 6, 2023
1 parent 4f54c3b commit 662574e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions shecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const (
)

// ErrLargePlainText is returned when the length of the input text is greater than 1<<40 - 1.
var ErrLargePlainText = errors.New("shecomp: the length of the input text is too large")
var ErrLargePlainText = errors.New("the length of the input text is too large. it must be less than 1<<40 - 1 in bit after decoding")

// ErrNeedPadding is returned when the input text is not multiple of block size.
var ErrNeedPadding = errors.New("shecomp: the input text must be multiple of block size")
var ErrNeedPadding = errors.New("the input text must be multiple of block size")

type blockReader interface {
block(dst []byte) error
Expand Down Expand Up @@ -146,7 +146,7 @@ func Padding(r io.Reader) ([]byte, error) {
if errors.Is(err, io.EOF) {
break
}
return nil, fmt.Errorf("error during padding: %w", err)
return nil, fmt.Errorf("failed to add padding: %w", err)
}
}
h := make([]byte, hex.EncodedLen(len(br.pad)))
Expand All @@ -170,11 +170,11 @@ func CompressWithoutPadding(r io.Reader) ([]byte, error) {

func encrypt(src, previous []byte) ([]byte, error) {
if len(src) != blockSize || len(previous) != blockSize {
return nil, fmt.Errorf("shecomp: failed to encrypt. the length of each input must be same as blockSize=%d, but len(src) = %d, len(previous) = %d", blockSize, len(src), len(previous))
return nil, fmt.Errorf("failed to encrypt. the length of each input must be same as blockSize=%d, but len(src) = %d, len(previous) = %d", blockSize, len(src), len(previous))
}
cipher, err := aes.NewCipher(previous)
if err != nil {
return nil, fmt.Errorf("shecomp: failed to create cipher: %w", err)
return nil, fmt.Errorf("failed to initialize aes cipher: %w", err)
}
encrypted := make([]byte, blockSize)
cipher.Encrypt(encrypted, src)
Expand All @@ -185,7 +185,7 @@ func encrypt(src, previous []byte) ([]byte, error) {

func xor(a, b []byte) ([]byte, error) {
if len(a) != len(b) {
return nil, fmt.Errorf("shecomp: failed to xor: len(a) = %d, len(b) = %d", len(a), len(b))
return nil, fmt.Errorf("failed to xor: len(a) = %d, len(b) = %d", len(a), len(b))
}
r := make([]byte, len(a))
for i := 0; i < len(a); i++ {
Expand Down

0 comments on commit 662574e

Please sign in to comment.