Skip to content

feat(crypto): add gsha256#4558

Merged
gqcn merged 5 commits intomasterfrom
feat/gsha256
Dec 12, 2025
Merged

feat(crypto): add gsha256#4558
gqcn merged 5 commits intomasterfrom
feat/gsha256

Conversation

@joy999
Copy link
Contributor

@joy999 joy999 commented Dec 11, 2025

This pull request introduces a new package, gsha256, providing SHA256 encryption utilities for both arbitrary data and file contents. It also adds comprehensive unit tests to ensure the correctness of these new APIs.

New SHA256 encryption utilities:

  • Added the gsha256 package with three main functions:
    • Encrypt: Hashes any variable using SHA256, converting input to bytes via gconv.
    • EncryptFile: Hashes the contents of a file at a given path, returning the SHA256 digest as a hex string. Errors are wrapped for clarity.
    • MustEncryptFile: Like EncryptFile, but panics on error for convenience in situations where failure is unexpected.

Unit tests for new functionality:

  • Added gsha256_z_unit_test.go to test the new APIs:
    • Verifies correct hash output for string and struct input to Encrypt.
    • Validates file hashing and error handling for non-existent files in EncryptFile.

@joy999 joy999 changed the title add gsha256 feature(crypto): add gsha256 Dec 11, 2025
@joy999 joy999 requested a review from Copilot December 11, 2025 06:49
Copy link
Contributor

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 pull request introduces a new gsha256 package that provides SHA256 hashing utilities for arbitrary data and file contents, following the established patterns in GoFrame's crypto packages (gsha1, gmd5). The implementation includes core hashing functions and comprehensive unit tests.

  • Added three main functions: Encrypt, EncryptFile, and MustEncryptFile for SHA256 hashing
  • Included unit tests covering string/struct hashing and file hashing scenarios
  • Followed consistent patterns with existing crypto packages in the codebase

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
crypto/gsha256/gsha256.go Implements the core SHA256 hashing functions with proper error handling and wrapping
crypto/gsha256/gsha256_z_unit_test.go Provides unit tests for the Encrypt and EncryptFile functions with edge case coverage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Dec 11, 2025

@joy999 I've opened a new pull request, #4560, to work on those changes. Once the pull request is ready, I'll request review from you.

joy999 and others added 2 commits December 11, 2025 14:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…le (#4560)

Updates #4558

Function comments in `gsha256` used lowercase "sha256 algorithms" while
sibling packages `gsha1` and `gmd5` use uppercase "SHA1 algorithms" and
"MD5 algorithms".

**Changes:**
- Capitalized "SHA256" in all function comments (`Encrypt`,
`EncryptFile`, `MustEncryptFile`)

This maintains consistency with the existing documentation style across
crypto packages.

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: joy999 <5414344+joy999@users.noreply.github.com>
Co-authored-by: Hunk Zhu <54zhua@gmail.com>
@gqcn
Copy link
Member

gqcn commented Dec 11, 2025

/lgtm

Copy link
Contributor

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gqcn gqcn merged commit 7274a73 into master Dec 12, 2025
20 checks passed
@gqcn gqcn deleted the feat/gsha256 branch December 12, 2025 07:15
@gqcn gqcn changed the title feature(crypto): add gsha256 feat(crypto): add gsha256 Dec 29, 2025
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.

4 participants