-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a resource leak introduced by #27069. - add defer - move sign code out of `repository.go`
- Loading branch information
Showing
3 changed files
with
44 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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)) | ||
} |