Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Oct 18, 2024
1 parent 470193e commit 1bb9d08
Show file tree
Hide file tree
Showing 5 changed files with 1,453 additions and 1,410 deletions.
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (p *sClient) DecryptMessage(pMsg []byte) (asymmetric.IDSAPubKey, []byte, er

// Load public key and check standart size.
signerPubKey := asymmetric.LoadDSAPubKey(pkey)
if signerPubKey == nil { // || pubKey.GetSize() != p.GetPubKey().GetSize()
if signerPubKey == nil {
return nil, nil, ErrDecodePublicKey
}

Expand Down
43 changes: 43 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,46 @@ func TestClient(t *testing.T) {
// fmt.Println(client.GetPayloadLimit(), client.GetMessageSize())
// fmt.Println(len(client.GetPrivKey().GetPubKey().ToString()))
}

func TestDecrypt(t *testing.T) {
t.Parallel()

client := NewClient(
asymmetric.NewPrivKey(),
(8 << 10),
)

if _, _, err := client.DecryptMessage([]byte{123}); err == nil {
t.Error("success decrypt with invalid ciphertext (1)")
return
}

kemPubKey := client.GetPrivKey().GetKEMPrivKey().GetPubKey()
msg := []byte("hello, world!")

enc, err := client.EncryptMessage(kemPubKey, msg)
if err != nil {
t.Error(err)
return
}

enc[0] ^= 1
if _, _, err := client.DecryptMessage(enc); err == nil {
t.Error("success decrypt with invalid ciphertext (2)")
return
}

enc[0] ^= 1
enc[len(enc)-1] ^= 1
if _, _, err := client.DecryptMessage(enc); err == nil {
t.Error("success decrypt with invalid ciphertext (3)")
return
}

enc[len(enc)-1] ^= 1
enc[len(enc)-2000] ^= 1
if _, _, err := client.DecryptMessage(enc); err == nil {
t.Error("success decrypt with invalid ciphertext (4)")
return
}
}
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1bb9d08

Please sign in to comment.