mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
956 B
39 lines
956 B
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package rpm
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"strings"
|
|
|
|
packages_module "code.gitea.io/gitea/modules/packages"
|
|
|
|
"github.com/ProtonMail/go-crypto/openpgp"
|
|
"github.com/sassoftware/go-rpmutils"
|
|
)
|
|
|
|
func SignPackage(buf *packages_module.HashedBuffer, privateKey string) (*packages_module.HashedBuffer, error) {
|
|
keyring, err := openpgp.ReadArmoredKeyRing(strings.NewReader(privateKey))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
h, err := rpmutils.SignRpmStream(buf, keyring[0].PrivateKey, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
signBlob, err := h.DumpSignatureHeader(false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if _, err := buf.Seek(int64(h.OriginalSignatureHeaderSize()), io.SeekStart); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// create new buf with signature prefix
|
|
return packages_module.CreateHashedBufferFromReader(io.MultiReader(bytes.NewReader(signBlob), buf))
|
|
}
|
|
|