Skip to content

Commit

Permalink
Merge pull request #69 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.6
  • Loading branch information
andyone authored Dec 12, 2024
2 parents 11fdd2f + 1bb9463 commit a75b624
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

strategy:
matrix:
go: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.x' ]
go: [ '1.22.x', '1.23.x' ]

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<br/>

`branca.go` is [branca token specification](https://github.com/tuupola/branca-spec) implementation for [Go 1.18+](https://github.com/essentialkaos/.github/blob/master/GO-VERSION-SUPPORT.md).
`branca.go` is [branca token specification](https://github.com/tuupola/branca-spec) implementation for [Go 1.22+](https://github.com/essentialkaos/.github/blob/master/GO-VERSION-SUPPORT.md).

Features and benefits:

Expand All @@ -27,7 +27,7 @@ Features and benefits:

### Installation

Make sure you have a working [Go 1.18+](https://github.com/essentialkaos/.github/blob/master/GO-VERSION-SUPPORT.md) workspace (_[instructions](https://go.dev/doc/install)_), then:
Make sure you have a working [Go 1.22+](https://github.com/essentialkaos/.github/blob/master/GO-VERSION-SUPPORT.md) workspace (_[instructions](https://go.dev/doc/install)_), then:


```bash
Expand Down
10 changes: 5 additions & 5 deletions branca.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
// KEY_SIZE is Branca key which is always 32 bytes (i.e 256 bit)
KEY_SIZE = 32

// MIN_TOKEN_SIZE is minimal token size is 45 bytes (with empty payload)
// MIN_TOKEN_SIZE is minimal token size in bytes (with empty payload)
MIN_TOKEN_SIZE = 45
)

Expand Down Expand Up @@ -94,7 +94,7 @@ func (t *Token) Payload() []byte {
return t.payload
}

// Timestamp returns token timestamp
// Timestamp returns token creation date
func (t *Token) Timestamp() time.Time {
return time.Unix(int64(t.ts), 0)
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (b Branca) Encode(payload []byte) ([]byte, error) {
return buf.Bytes(), nil
}

// Decode extract payload from branca token
// Decode extracts payload from branca token
func (b Branca) Decode(token []byte) (Token, error) {
if len(b) != KEY_SIZE {
return Token{}, ErrBadKeyLength
Expand All @@ -159,7 +159,7 @@ func (b Branca) Decode(token []byte) (Token, error) {
return Token{payload, binary.BigEndian.Uint32(token[VERSION_SIZE : VERSION_SIZE+TIMESTAMP_SIZE])}, nil
}

// EncodeToString create Base62 encoded token with given payload
// EncodeToString creates Base62 encoded token with given payload
func (b Branca) EncodeToString(payload []byte) (string, error) {
token, err := b.Encode(payload)

Expand All @@ -170,7 +170,7 @@ func (b Branca) EncodeToString(payload []byte) (string, error) {
return EncodeBase62(token), nil
}

// DecodeString extract payload from Base62 encoded token
// DecodeString extracts payload from Base62 encoded token
func (b Branca) DecodeString(token string) (Token, error) {
data, err := DecodeBase62(token)

Expand Down
7 changes: 5 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func ExampleToken_IsExpired() {
return
}

fmt.Printf("Token expired: %t", token.IsExpired(0))
// Output: Token expired: true
fmt.Printf("Token expired (TTL: 0): %t\n", token.IsExpired(0))
fmt.Printf("Token expired (TTL: 10 years): %t\n", token.IsExpired(3600*24*365*10))
// Output:
// Token expired (TTL: 0): true
// Token expired (TTL: 10 years): false
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/essentialkaos/branca/v2

go 1.18
go 1.22

require (
github.com/essentialkaos/check v1.4.0
golang.org/x/crypto v0.28.0
github.com/essentialkaos/check v1.4.1
golang.org/x/crypto v0.31.0
)

require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/sys v0.26.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
golang.org/x/sys v0.28.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0=
github.com/essentialkaos/check v1.4.1 h1:SuxXzrbokPGTPWxGRnzy0hXvtb44mtVrdNxgPa1s4c8=
github.com/essentialkaos/check v1.4.1/go.mod h1:xQOYwFvnxfVZyt5Qvjoa1SxcRqu5VyP77pgALr3iu+M=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit a75b624

Please sign in to comment.