gitlab.com/aquachain/aquachain@v1.17.16-rc3.0.20221018032414-e3ddf1e1c055/internal/build/pgp.go (about)

     1  // Copyright 2018 The aquachain Authors
     2  // This file is part of the aquachain library.
     3  //
     4  // The aquachain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The aquachain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the aquachain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // signFile reads the contents of an input file and signs it (in armored format)
    18  // with the key provided, placing the signature into the output file.
    19  
    20  package build
    21  
    22  // "bytes"
    23  // "fmt"
    24  // "os"
    25  
    26  // "golang.org/x/crypto/openpgp"
    27  
    28  // PGPSignFile parses a PGP private key from the specified string and creates a
    29  // signature file into the output parameter of the input file.
    30  //
    31  // Note, this method assumes a single key will be container in the pgpkey arg,
    32  // furthermore that it is in armored format.
    33  // func PGPSignFile(input string, output string, pgpkey string) error {
    34  // 	// Parse the keyring and make sure we only have a single private key in it
    35  // 	keys, err := openpgp.ReadArmoredKeyRing(bytes.NewBufferString(pgpkey))
    36  // 	if err != nil {
    37  // 		return err
    38  // 	}
    39  // 	if len(keys) != 1 {
    40  // 		return fmt.Errorf("key count mismatch: have %d, want %d", len(keys), 1)
    41  // 	}
    42  // 	// Create the input and output streams for signing
    43  // 	in, err := os.Open(input)
    44  // 	if err != nil {
    45  // 		return err
    46  // 	}
    47  // 	defer in.Close()
    48  
    49  // 	out, err := os.Create(output)
    50  // 	if err != nil {
    51  // 		return err
    52  // 	}
    53  // 	defer out.Close()
    54  
    55  // 	// Generate the signature and return
    56  // 	return openpgp.ArmoredDetachSign(out, keys[0], in, nil)
    57  // }