chore: modernize import (#7170)
Since go1.24 this is available in the standard library, error values were added to the API. We simply continue to panic on error. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7170 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
7c05c8faac
commit
a479fef432
|
@ -16,12 +16,12 @@
|
|||
package keying
|
||||
|
||||
import (
|
||||
"crypto/hkdf"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
|
||||
"golang.org/x/crypto/chacha20poly1305"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -41,7 +41,11 @@ const (
|
|||
// Set the main IKM for this module.
|
||||
func Init(ikm []byte) {
|
||||
// Salt is intentionally left empty, it's not useful to Forgejo's use case.
|
||||
prk = hkdf.Extract(hash, ikm, nil)
|
||||
var err error
|
||||
prk, err = hkdf.Extract(hash, ikm, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Specifies the context for which a subkey should be derived for.
|
||||
|
@ -62,11 +66,8 @@ func DeriveKey(context Context) *Key {
|
|||
panic("keying: not initialized")
|
||||
}
|
||||
|
||||
r := hkdf.Expand(hash, prk, []byte(context))
|
||||
|
||||
key := make([]byte, aeadKeySize)
|
||||
// This should never return an error, but if it does, panic.
|
||||
if n, err := r.Read(key); err != nil || n != aeadKeySize {
|
||||
key, err := hkdf.Expand(hash, prk, string(context), aeadKeySize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue