-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18830f7
commit ce77f9c
Showing
18 changed files
with
384 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,8 @@ go.work | |
|
||
# go executable file output | ||
main | ||
|
||
# secret files | ||
PRIVATE_KEY | ||
PUBLIC_KEY | ||
SIGN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2024 Berk Kirtay | ||
|
||
package commands | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func dumpToFile(data string, fileName string) { | ||
file, err := os.Create(fileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = file.Write([]byte(data)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file.Close() | ||
} | ||
|
||
func readFromFile(fileName string) string { | ||
data, err := os.ReadFile(fileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return string(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2024 Berk Kirtay | ||
|
||
package cryptography | ||
|
||
type Cryptography struct { | ||
Sign string `json:"sign,omitempty" bson:"sign,omitempty"` | ||
PublicKey string `json:"publicKey,omitempty" bson:"publicKey,omitempty"` | ||
PrivateKey string `json:"privateKey,omitempty" bson:"privateKey,omitempty"` | ||
Nonce int64 `json:"nonce,omitempty" bson:"nonce,omitempty"` | ||
Timestamp string `json:"timestamp,omitempty" bson:"timestamp,omitempty"` | ||
Hash string `json:"hash,omitempty" bson:"hash,omitempty"` | ||
} | ||
|
||
type CryptographyOption func(Cryptography) Cryptography | ||
|
||
func WithSign(sign string) CryptographyOption { | ||
return func(Cryptography Cryptography) Cryptography { | ||
Cryptography.Sign = sign | ||
return Cryptography | ||
} | ||
} | ||
|
||
func WithPublicKey(publicKey string) CryptographyOption { | ||
return func(Cryptography Cryptography) Cryptography { | ||
Cryptography.PublicKey = publicKey | ||
return Cryptography | ||
} | ||
} | ||
|
||
func WithPrivateKey(privateKey string) CryptographyOption { | ||
return func(Cryptography Cryptography) Cryptography { | ||
Cryptography.PrivateKey = privateKey | ||
return Cryptography | ||
} | ||
} | ||
|
||
func WithNonce(nonce int64) CryptographyOption { | ||
return func(Cryptography Cryptography) Cryptography { | ||
Cryptography.Nonce = nonce | ||
return Cryptography | ||
} | ||
} | ||
|
||
func WithTimestamp(timestamp string) CryptographyOption { | ||
return func(Cryptography Cryptography) Cryptography { | ||
Cryptography.Timestamp = timestamp | ||
return Cryptography | ||
} | ||
} | ||
|
||
func WithHash(hash string) CryptographyOption { | ||
return func(Cryptography Cryptography) Cryptography { | ||
Cryptography.Hash = hash | ||
return Cryptography | ||
} | ||
} | ||
|
||
func CreateDefaultCryptography() Cryptography { | ||
return Cryptography{} | ||
} | ||
|
||
func CreateCryptography(options ...CryptographyOption) *Cryptography { | ||
Cryptography := CreateDefaultCryptography() | ||
|
||
for _, option := range options { | ||
Cryptography = option(Cryptography) | ||
} | ||
|
||
return &Cryptography | ||
} |
Oops, something went wrong.