Skip to content

Commit

Permalink
add default algorithm. now, algorithm is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
juunini committed Oct 29, 2023
1 parent cc02372 commit 0b9607f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ message := []byte(`{

headers, err := signature_header.Generate(signature_header.GenerateInput{
PrivateKeyBytes: []byte("-----BEGIN RSA PRIVATE KEY-----..."),
Algorithm: crypto.SHA256,
// Algorithm: crypto.SHA256, // optional. if not set, default is crypto.SHA256
Host: requestURL.Host,
Path: requestURL.Path,
Body: message,
Expand Down
8 changes: 7 additions & 1 deletion generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package signature_header

import "crypto"
import (
"crypto"
)

/*
Example:
Expand Down Expand Up @@ -41,6 +43,10 @@ Example:
})
*/
func Generate(input GenerateInput) (*GenerateOutput, error) {
if input.Algorithm == 0 {
input.Algorithm = crypto.SHA256
}

date := Date()
digest := Digest(input.Algorithm, input.Body)

Expand Down
3 changes: 0 additions & 3 deletions test/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package signature_header_test

import (
"context"
"crypto"
"crypto/x509"
"encoding/pem"
"fmt"
Expand Down Expand Up @@ -85,11 +84,9 @@ func createSignature() map[string]string {
const host = "snippet.social"
const path = "/@juunini/inbox"
const keyID = "http://localhost:8000/@juunini#main-key"
const algorithm = crypto.SHA256

headers, err := signature_header.Generate(signature_header.GenerateInput{
PrivateKeyBytes: []byte(privateKeyStr),
Algorithm: algorithm,
Host: host,
Path: path,
Body: message,
Expand Down

0 comments on commit 0b9607f

Please sign in to comment.