mirror of
1
Fork 0

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:
Gusted 2025-03-11 13:31:31 +00:00 committed by Gusted
parent 7c05c8faac
commit a479fef432
1 changed files with 8 additions and 7 deletions

View File

@ -16,12 +16,12 @@
package keying package keying
import ( import (
"crypto/hkdf"
"crypto/rand" "crypto/rand"
"crypto/sha256" "crypto/sha256"
"encoding/binary" "encoding/binary"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/hkdf"
) )
var ( var (
@ -41,7 +41,11 @@ const (
// Set the main IKM for this module. // Set the main IKM for this module.
func Init(ikm []byte) { func Init(ikm []byte) {
// Salt is intentionally left empty, it's not useful to Forgejo's use case. // 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. // Specifies the context for which a subkey should be derived for.
@ -62,11 +66,8 @@ func DeriveKey(context Context) *Key {
panic("keying: not initialized") panic("keying: not initialized")
} }
r := hkdf.Expand(hash, prk, []byte(context)) key, err := hkdf.Expand(hash, prk, string(context), aeadKeySize)
if err != nil {
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 {
panic(err) panic(err)
} }