forked from TrueCloudLab/frostfs-http-gw
app: add support for ephemeral keys
This commit is contained in:
parent
1156223231
commit
c06a3137e5
4 changed files with 36 additions and 3 deletions
|
@ -2,6 +2,9 @@ package neofs
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
|
@ -33,6 +36,25 @@ func NewCredentials(secret string) (Credentials, error) {
|
|||
return setFromPrivateKey(key)
|
||||
}
|
||||
|
||||
// NewEphemeralCredentials creates new private key and Credentials based on that
|
||||
// key.
|
||||
func NewEphemeralCredentials() (Credentials, error) {
|
||||
c := elliptic.P256()
|
||||
priv, x, y, err := elliptic.GenerateKey(c, rand.Reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
key := &ecdsa.PrivateKey{
|
||||
PublicKey: ecdsa.PublicKey{
|
||||
Curve: c,
|
||||
X: x,
|
||||
Y: y,
|
||||
},
|
||||
D: new(big.Int).SetBytes(priv),
|
||||
}
|
||||
return setFromPrivateKey(key)
|
||||
}
|
||||
|
||||
// PrivateKey returns ecdsa.PrivateKey.
|
||||
func (c *credentials) PrivateKey() *ecdsa.PrivateKey {
|
||||
return c.key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue