Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 16 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
name: Tests
on: push
on: [push]

jobs:

lint:
name: lint
tests:
name: Test suite
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.25"]

steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v5

- uses: actions/setup-go@v6
with:
go-version: 1.17
- uses: actions/checkout@v3
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v9
with:
version: v1.29
skip-cache: true
skip-build-cache: true
version: v2.6

gosec:
name: security scanner
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...

tests:
name: Test suite
runs-on: ubuntu-latest

steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
- uses: actions/checkout@v3

- name: Tests
run: go test -count=1 -timeout 240s -race -cover ./...

run: go test -count=1 -timeout 240s -race -cover ./...
- name: Build lkgen
run: cd lkgen && go build
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Hyperboloide
Copyright (c) 2025 Frederic Delbos

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 13 additions & 12 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Example_complete() {
// create a new Private key:
privateKey, err := lk.NewPrivateKey()
if err != nil {
log.Fatal(err)
log.Fatal("private key generation failed: " + err.Error())

}

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

}

// encode the new license to b64, this is what you give to your customer.
str64, err := license.ToB64String()
if err != nil {
log.Fatal(err)

}
fmt.Println(str64)

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

// validate the license:
if ok, err := license.Verify(publicKey); err != nil {
log.Fatal(err)
log.Fatal("license verification failed: " + err.Error())
} else if !ok {
log.Fatal("Invalid license signature")
}
Expand Down Expand Up @@ -101,22 +100,24 @@ func Example_licenseGeneration() {
// Unmarshal the private key:
privateKey, err := lk.PrivateKeyFromB32String(privateKeyBase32)
if err != nil {
log.Fatal(err)
log.Fatal("private key unmarshal failed: " + err.Error())
}

// generate your license with the private key and the document:
license, err := lk.NewLicense(privateKey, docBytes)
if err != nil {
log.Fatal(err)

log.Fatal("license generation failed: " + err.Error())
}

// the b32 representation of our license, this is what you give to
// your customer.
licenseB32, err := license.ToB32String()
if err != nil {
log.Fatal(err)
log.Fatal("license encoding failed: " + err.Error())

}

// print the license that you should give to your customer
fmt.Println(licenseB32)
}

Expand All @@ -125,7 +126,7 @@ func Example_licenseGeneration() {
func Example_licenseVerification() {

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

Expand All @@ -137,18 +138,18 @@ func Example_licenseVerification() {
// Unmarshal the public key
publicKey, err := lk.PublicKeyFromB32String(publicKeyBase32)
if err != nil {
log.Fatal(err)
log.Fatal("public key unmarshal failed: " + err.Error())
}

// Unmarshal the customer license:
license, err := lk.LicenseFromB32String(licenseB32)
if err != nil {
log.Fatal(err)
log.Fatal("license unmarshal failed: " + err.Error())
}

// validate the license signature:
if ok, err := license.Verify(publicKey); err != nil {
log.Fatal(err)
log.Fatal("license verification failed: " + err.Error())
} else if !ok {
log.Fatal("Invalid license signature")
}
Expand Down
17 changes: 5 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ module github.com/hyperboloide/lk

go 1.17

require gopkg.in/alecthomas/kingpin.v2 v2.2.6

require (
github.com/dchest/uniuri v0.0.0-20220929095258-3027df40b6ce
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.20.2
gopkg.in/alecthomas/kingpin.v2 v2.2.6
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/nxadm/tail v1.4.8 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/stretchr/testify v1.11.1
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading