Initial commit - test client
This commit is contained in:
commit
c099930cf3
8 changed files with 137 additions and 0 deletions
39
client/client.go
Normal file
39
client/client.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/ecdsa"
|
||||
"crypto/ed25519"
|
||||
"crypto/rsa"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/common-fate/httpsig"
|
||||
"github.com/common-fate/httpsig/alg_ecdsa"
|
||||
"github.com/common-fate/httpsig/alg_ed25519"
|
||||
"github.com/common-fate/httpsig/alg_rsa"
|
||||
"github.com/common-fate/httpsig/signer"
|
||||
)
|
||||
|
||||
func GetSigningClient(key crypto.PrivateKey, keyId string) (*http.Client, error) {
|
||||
var alg signer.Algorithm
|
||||
|
||||
switch p := key.(type) {
|
||||
case *rsa.PrivateKey:
|
||||
alg = alg_rsa.NewRSAPKCS256Signer(p)
|
||||
case *ed25519.PrivateKey:
|
||||
alg = alg_ed25519.Ed25519{PrivateKey: *p}
|
||||
case *ecdsa.PrivateKey:
|
||||
alg = alg_ecdsa.NewP256Signer(p)
|
||||
default:
|
||||
return nil, fmt.Errorf("type is unknown: %s", reflect.TypeOf(key))
|
||||
}
|
||||
|
||||
client := httpsig.NewClient(httpsig.ClientOpts{
|
||||
KeyID: keyId,
|
||||
Alg: alg,
|
||||
})
|
||||
|
||||
return client, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue