Skip to content

Commit 400ab38

Browse files
committed
Update version to 0.2.2, and update documentation and test cases.
1 parent ea8fab4 commit 400ab38

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
strategy:
1515
matrix:
1616
ruby:
17+
- '3.4'
18+
- '3.3'
1719
- '3.2'
1820
- '3.1'
1921
- '3.0'

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
## [Unreleased]
22

3+
## [0.2.2] - 2025-03-26
4+
5+
- Add ASN.1 DER format for sm2 sign and verify
6+
7+
## [0.2.0] - 2023-04-21
8+
9+
- Add sm2 sign and verify support
10+
311
## [0.1.0] - 2023-03-27
412

513
- Initial release

Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
sm2-crypto (0.2.1)
4+
sm2-crypto (0.2.2)
55

66
GEM
77
remote: https://rubygems.org/
@@ -11,6 +11,7 @@ GEM
1111

1212
PLATFORMS
1313
arm64-darwin-22
14+
arm64-darwin-24
1415
x86_64-linux
1516

1617
DEPENDENCIES

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,17 @@ sign = SM2Crypto.sign(private_key, message)
5959
# verify signatrue
6060
SM2Crypto.verify(public_key, message, sign)
6161

62-
user_id = "31323334353637383132333435363738" # user_id should be a hex string
62+
# user_id should be a hex string, default: "31323334353637383132333435363738" which is equal to utf-8 string: "1234567812345678"
63+
user_id = "31323334353637383132333435363738"
6364
# sign with hash and user_id
6465
sign = SM2Crypto.sign(private_key, message, sm3_hash: true, user_id: user_id)
6566
# verify with hash and user_id
6667
SM2Crypto.verify(public_key, message, sign, sm3_hash: true, user_id: user_id)
68+
69+
# sign with ASN.1 DER format output
70+
sign = SM2Crypto.sign(private_key, message, asn1: true)
71+
# verify signatrue
72+
SM2Crypto.verify(public_key, message, sign, asn1: true)
6773
```
6874

6975
### Get Public Key from Private Key

lib/sm2_crypto.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def sign(private_key, data, sm3_hash: false, user_id: "3132333435363738313233343
149149
# @return [Boolean] verify result
150150
def verify(public_key, data, signature, sm3_hash: false, user_id: "31323334353637383132333435363738", asn1: false)
151151
if asn1
152-
# return false if signature.size < 138
152+
return false if signature.size < 136
153153

154154
# parse asn1 der format hex string signature
155155
der_seq = OpenSSL::ASN1.decode([signature].pack("H*"))

sm2-crypto.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = "sm2-crypto"
5-
spec.version = "0.2.1"
5+
spec.version = "0.2.2"
66
spec.authors = ["Seekr"]
77
spec.email = ["[email protected]"]
88

test/test_sm2_crypto.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ def test_sign_and_verify_with_asn1
101101
msg = SecureRandom.alphanumeric(rand(1..100))
102102
sign = SM2Crypto.sign(SM2_PRIVATE_KEY, msg, asn1: true)
103103
verified = SM2Crypto.verify(SM2_PUBLIC_KEY, msg, sign, asn1: true)
104-
unless verified
105-
puts "msg: #{msg}"
106-
puts "sign: #{sign}"
107-
end
108104
assert_equal true, verified
109105
end
110106
end

0 commit comments

Comments
 (0)