Skip to content

feat:Add AES-GCM encryption and decryption utilities with tests#237

Merged
inhere merged 3 commits intogookit:masterfrom
betterlmy:feat-gcm
Mar 16, 2026
Merged

feat:Add AES-GCM encryption and decryption utilities with tests#237
inhere merged 3 commits intogookit:masterfrom
betterlmy:feat-gcm

Conversation

@betterlmy
Copy link
Copy Markdown
Contributor

This pull request introduces AES-GCM encryption and decryption utilities to the secutil package, along with comprehensive tests to ensure correct functionality and error handling. The most important changes are grouped below:

AES-GCM Encryption/Decryption Implementation:

  • Added the EncryptGCM and DecryptGCM functions to aes_gcm.go for encrypting and decrypting data using AES-GCM, including random nonce generation and key validation.
  • Introduced error variables ErrInvalidAESKeySize and ErrInvalidGCMNonceSize for precise error reporting on invalid key and nonce sizes.

Testing and Validation:

  • Added aes_gcm_test.go with tests covering valid AES key sizes, empty plaintext handling, and error cases for invalid key and nonce sizes, ensuring robust functionality and edge case coverage.
  • Tests verify that decryption fails with incorrect keys or nonce sizes, and that encryption rejects invalid key lengths.

Implement AES-GCM encryption and decryption functions with key and nonce validation.
Copilot AI review requested due to automatic review settings March 14, 2026 08:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds AES-GCM encryption/decryption helpers to the x/encodes/secutil package, along with unit tests to validate round-trip behavior and key/nonce validation.

Changes:

  • Introduced EncryptGCM and DecryptGCM utilities backed by crypto/cipher AES-GCM.
  • Added sentinel errors for invalid AES key sizes and invalid GCM nonce sizes.
  • Added tests covering valid AES key sizes, empty plaintext, and invalid key/nonce error paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
x/encodes/secutil/aes_gcm.go Adds AES-GCM encrypt/decrypt helpers with key-size validation and nonce generation.
x/encodes/secutil/aes_gcm_test.go Adds unit tests for round-trip encryption/decryption and error handling.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@betterlmy
Copy link
Copy Markdown
Contributor Author

Hi @inhere, please take a look at this PR when you have a moment. Thanks!

@inhere inhere merged commit 6ce8156 into gookit:master Mar 16, 2026
16 checks passed
@betterlmy betterlmy deleted the feat-gcm branch March 16, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants