2018-11-15 12:25:04 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-14 10:50:15 +00:00
|
|
|
package satelliteauth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/hmac"
|
|
|
|
"crypto/sha256"
|
|
|
|
)
|
|
|
|
|
|
|
|
//TODO: change to JWT or Macaroon based auth
|
|
|
|
|
|
|
|
// Hmac is hmac256 based Signer
|
|
|
|
type Hmac struct {
|
|
|
|
Secret []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sign implements satellite signer
|
|
|
|
func (a *Hmac) Sign(data []byte) ([]byte, error) {
|
|
|
|
mac := hmac.New(sha256.New, a.Secret)
|
|
|
|
|
|
|
|
_, err := mac.Write(data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return mac.Sum(nil), nil
|
|
|
|
}
|