-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
3 changed files
with
93 additions
and
1 deletion.
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
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,49 @@ | ||
package github | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/base64" | ||
"fmt" | ||
"time" | ||
|
||
"golang.org/x/crypto/nacl/box" | ||
) | ||
|
||
type RepositorySecrets struct { | ||
TotalCount int `json:"total_count"` | ||
Secrets []RepositorySecret `json:"secrets"` | ||
} | ||
|
||
type RepositorySecret struct { | ||
Name string `json:"name"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
} | ||
|
||
type RepositoryPublicKey struct { | ||
KeyID string `json:"key_id"` | ||
Key string `json:"key"` | ||
} | ||
|
||
type OverrideRepositorySecret struct { | ||
EncryptedValue string `json:"encrypted_value"` | ||
KeyID string `json:"key_id"` | ||
} | ||
|
||
func (c *GitHubClient) encryptSecretWithSodium(pkBase64, clearText string) (string, error) { | ||
// adapted from implementation by Sterling Hanenkamp (c) 2022 | ||
// See https://zostay.com/posts/2022/05/04/do-not-use-libsodium-with-go/ | ||
var pkBytes [32]byte | ||
_, err := base64.StdEncoding.Decode(pkBytes[:], []byte(pkBase64)) | ||
if err != nil { | ||
return "", fmt.Errorf("public key: %w", err) | ||
} | ||
raw := []byte(clearText) | ||
out := make([]byte, 0, len(raw)+box.Overhead+len(pkBytes)) | ||
encryptedRaw, err := box.SealAnonymous(out, raw, &pkBytes, rand.Reader) | ||
if err != nil { | ||
return "", err | ||
} | ||
encoded := base64.StdEncoding.EncodeToString(encryptedRaw) | ||
return encoded, nil | ||
} |
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