Skip to content

Commit

Permalink
Merge pull request #1 from oxipass/fix-oxicrypt
Browse files Browse the repository at this point in the history
refactoring oxicrypt usage + some tests
  • Loading branch information
bykovme authored Feb 26, 2023
2 parents 7554c55 + fa3b413 commit 54fddc4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ assets/fa/.DS_Store

.vscode/
.idea/
oxilib.test
profile*.png
mem.prof

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/oxipass/oxilib
go 1.18

require (
github.com/mattn/go-sqlite3 v1.14.5
github.com/oxipass/oxicrypt v1.0.6
github.com/mattn/go-sqlite3 v1.14.16
github.com/oxipass/oxicrypt v1.0.8
)

require golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
require golang.org/x/crypto v0.6.0 // indirect
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
github.com/oxipass/oxicrypt v1.0.6 h1:KancTlpiBf3ocjX4V6I77LxEASjWmiwPGU8Y+khcxV0=
github.com/oxipass/oxicrypt v1.0.6/go.mod h1:cM/TsbQ4WVc++INX6BpL5CNAXS6mhNNJlfFUn15v5oM=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/oxipass/oxicrypt v1.0.7 h1:3LedPnSIziocFgSp/TCeuI5w5d3jT+uWQZKtUkwObSg=
github.com/oxipass/oxicrypt v1.0.7/go.mod h1:cM/TsbQ4WVc++INX6BpL5CNAXS6mhNNJlfFUn15v5oM=
github.com/oxipass/oxicrypt v1.0.8 h1:0iXCPjxX+3babiUy1GrncoBaQLzXlrEynqpSewm98tg=
github.com/oxipass/oxicrypt v1.0.8/go.mod h1:1XqUyox7sqgLrA9Mo4nucC2lZxZBbMyrexxDmHpB0tw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/security/encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package security
import "github.com/oxipass/oxicrypt"

type OxiEncryptor struct {
Cipher oxicrypt.BSCipher
Cipher oxicrypt.OxiCipher
CryptID string
}
21 changes: 13 additions & 8 deletions internal/pkg/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import (

func (enc OxiEncryptor) GetCypherNames() []string {
var lCyphers []string
for _, cypher := range oxicrypt.Ciphers {
lCyphers = append(lCyphers, cypher.GetCipherName())
for _, cypher := range oxicrypt.GetCiphers() {
lCyphers = append(lCyphers, cypher.Description)
}
return lCyphers
}

func (enc *OxiEncryptor) Init(cryptID string) error {
for _, cypher := range oxicrypt.Ciphers {
if cypher.GetCryptID() == cryptID {
enc.Cipher = cypher
for _, cipher := range oxicrypt.GetCiphers() {
if cipher.ID == cryptID {
var initError error
enc.Cipher, initError = oxicrypt.GetOxiCipher(cipher.ID)
if initError != nil {
return oxierr.FormError(oxierr.BSERR00004EncCypherNotExist,
"OxiEncryptor.Init", "CryptID: "+cryptID+", oxicrypt: "+initError.Error())
}
enc.CryptID = cryptID
enc.Cipher.CleanAndInit()
return nil
Expand All @@ -26,9 +31,9 @@ func (enc *OxiEncryptor) Init(cryptID string) error {
}

func (enc OxiEncryptor) GetCryptIDbyName(cypherName string) (string, error) {
for _, cypher := range oxicrypt.Ciphers {
if cypher.GetCipherName() == cypherName {
return cypher.GetCryptID(), nil
for _, cypher := range oxicrypt.GetCiphers() {
if cypher.Description == cypherName {
return cypher.ID, nil
}
}
return "", oxierr.FormError(oxierr.BSERR00004EncCypherNotExist, "OxiEncryptor.getCryptIDbyName", "cypherName: "+cypherName)
Expand Down
11 changes: 11 additions & 0 deletions oxi_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ func testHelperCreateItemAndField() (itemId int64, fieldId int64, err error) {
return itemId, fieldId, nil
}

func BenchmarkAddField(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _, err := testHelperCreateItemAndField()
if err != nil {
b.Error(err)
b.FailNow()
return
}
}
}

func TestAddField(t *testing.T) {
itemId, fieldId, err := testHelperCreateItemAndField()
if err != nil {
Expand Down

0 comments on commit 54fddc4

Please sign in to comment.