Skip to content

Commit b291812

Browse files
authored
updated code to remove deprecated funcs and refactor tests (#10)
1 parent ce3fecd commit b291812

10 files changed

Lines changed: 257 additions & 380 deletions

File tree

.github/workflows/tests.yml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
11
name: Tests
2-
on: push
2+
on: [push]
33

44
jobs:
55

6-
lint:
7-
name: lint
6+
tests:
7+
name: Test suite
88
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
go-version: ["1.25"]
12+
913
steps:
10-
- uses: actions/setup-go@v3
14+
- uses: actions/checkout@v5
15+
16+
- uses: actions/setup-go@v6
1117
with:
12-
go-version: 1.17
13-
- uses: actions/checkout@v3
18+
go-version: stable
1419
- name: golangci-lint
15-
uses: golangci/golangci-lint-action@v3
20+
uses: golangci/golangci-lint-action@v9
1621
with:
17-
version: v1.29
18-
skip-cache: true
19-
skip-build-cache: true
22+
version: v2.6
2023

21-
gosec:
22-
name: security scanner
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v3
2624
- name: Run Gosec Security Scanner
2725
uses: securego/gosec@master
2826
with:
2927
args: ./...
30-
31-
tests:
32-
name: Test suite
33-
runs-on: ubuntu-latest
34-
35-
steps:
36-
- uses: actions/setup-go@v3
37-
with:
38-
go-version: 1.17
39-
- uses: actions/checkout@v3
28+
4029
- name: Tests
41-
run: go test -count=1 -timeout 240s -race -cover ./...
42-
30+
run: go test -count=1 -timeout 240s -race -cover ./...
31+
4332
- name: Build lkgen
4433
run: cd lkgen && go build

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Hyperboloide
3+
Copyright (c) 2025 Frederic Delbos
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

examples_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Example_complete() {
1919
// create a new Private key:
2020
privateKey, err := lk.NewPrivateKey()
2121
if err != nil {
22-
log.Fatal(err)
22+
log.Fatal("private key generation failed: " + err.Error())
2323

2424
}
2525

@@ -39,15 +39,14 @@ func Example_complete() {
3939
// generate your license with the private key and the document:
4040
license, err := lk.NewLicense(privateKey, docBytes)
4141
if err != nil {
42-
log.Fatal(err)
42+
log.Fatal("license generation failed: " + err.Error())
4343

4444
}
4545

4646
// encode the new license to b64, this is what you give to your customer.
4747
str64, err := license.ToB64String()
4848
if err != nil {
4949
log.Fatal(err)
50-
5150
}
5251
fmt.Println(str64)
5352

@@ -57,7 +56,7 @@ func Example_complete() {
5756

5857
// validate the license:
5958
if ok, err := license.Verify(publicKey); err != nil {
60-
log.Fatal(err)
59+
log.Fatal("license verification failed: " + err.Error())
6160
} else if !ok {
6261
log.Fatal("Invalid license signature")
6362
}
@@ -101,22 +100,24 @@ func Example_licenseGeneration() {
101100
// Unmarshal the private key:
102101
privateKey, err := lk.PrivateKeyFromB32String(privateKeyBase32)
103102
if err != nil {
104-
log.Fatal(err)
103+
log.Fatal("private key unmarshal failed: " + err.Error())
105104
}
106105

107106
// generate your license with the private key and the document:
108107
license, err := lk.NewLicense(privateKey, docBytes)
109108
if err != nil {
110-
log.Fatal(err)
111-
109+
log.Fatal("license generation failed: " + err.Error())
112110
}
111+
113112
// the b32 representation of our license, this is what you give to
114113
// your customer.
115114
licenseB32, err := license.ToB32String()
116115
if err != nil {
117-
log.Fatal(err)
116+
log.Fatal("license encoding failed: " + err.Error())
118117

119118
}
119+
120+
// print the license that you should give to your customer
120121
fmt.Println(licenseB32)
121122
}
122123

@@ -125,7 +126,7 @@ func Example_licenseGeneration() {
125126
func Example_licenseVerification() {
126127

127128
// A previously generated licence b32 encoded. In real life you should read
128-
// it from a file at the beginning of your program and check it
129+
// it from a file (or prompt the user) at the beginning of your program and check it
129130
// before doing anything else...
130131
const licenseB32 = "FT7YOAYBAEDUY2LDMVXHGZIB76EAAAIDAECEIYLUMEAQUAABAFJAD74EAAAQCUYB76CAAAAABL7YGBIBAL7YMAAAAD73H74IAFEHWITFNVQWS3BCHIRHIZLTORAGK6DBNVYGYZJOMNXW2IRMEJSW4ZBCHIRDEMBRHAWTCMBNGI3FIMJSHIYTSORTGMXDOMBZG43TIMJYHAVTAMR2GAYCE7IBGEBAPXB37ROJCUOYBVG4LAL3MSNKJKPGIKNT564PYK5X542NH62V7TAUEYHGLEOPZHRBAPH7M4SC55OHAEYQEXMKGG3JPO6BSHTDF3T5H6T42VUD7YAJ3TY5AP5MDE5QW4ZYWMSAPEK24HZOUXQ3LJ5YY34XYPVXBUAA===="
131132

@@ -137,18 +138,18 @@ func Example_licenseVerification() {
137138
// Unmarshal the public key
138139
publicKey, err := lk.PublicKeyFromB32String(publicKeyBase32)
139140
if err != nil {
140-
log.Fatal(err)
141+
log.Fatal("public key unmarshal failed: " + err.Error())
141142
}
142143

143144
// Unmarshal the customer license:
144145
license, err := lk.LicenseFromB32String(licenseB32)
145146
if err != nil {
146-
log.Fatal(err)
147+
log.Fatal("license unmarshal failed: " + err.Error())
147148
}
148149

149150
// validate the license signature:
150151
if ok, err := license.Verify(publicKey); err != nil {
151-
log.Fatal(err)
152+
log.Fatal("license verification failed: " + err.Error())
152153
} else if !ok {
153154
log.Fatal("Invalid license signature")
154155
}

go.mod

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@ module github.com/hyperboloide/lk
22

33
go 1.17
44

5+
require gopkg.in/alecthomas/kingpin.v2 v2.2.6
6+
57
require (
6-
github.com/dchest/uniuri v0.0.0-20220929095258-3027df40b6ce
7-
github.com/onsi/ginkgo v1.16.5
8-
github.com/onsi/gomega v1.20.2
9-
gopkg.in/alecthomas/kingpin.v2 v2.2.6
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
1010
)
1111

1212
require (
1313
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
1414
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
15-
github.com/fsnotify/fsnotify v1.4.9 // indirect
16-
github.com/google/go-cmp v0.5.8 // indirect
17-
github.com/nxadm/tail v1.4.8 // indirect
18-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
19-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
20-
golang.org/x/text v0.3.7 // indirect
21-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
22-
gopkg.in/yaml.v2 v2.4.0 // indirect
15+
github.com/stretchr/testify v1.11.1
2316
gopkg.in/yaml.v3 v3.0.1 // indirect
2417
)

0 commit comments

Comments
 (0)