Example usage for org.eclipse.jgit.transport PushCertificateParser PushCertificateParser

List of usage examples for org.eclipse.jgit.transport PushCertificateParser PushCertificateParser

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport PushCertificateParser PushCertificateParser.

Prototype

public PushCertificateParser(Repository into, SignedPushConfig cfg) 

Source Link

Document

Constructor for PushCertificateParser.

Usage

From source file:com.google.gerrit.gpg.PushCertificateCheckerTest.java

License:Apache License

private PushCertificate newSignedCert(String nonce, TestKey signingKey) throws Exception {
    PushCertificateIdent ident = new PushCertificateIdent(signingKey.getFirstUserId(),
            System.currentTimeMillis(), -7 * 60);
    String payload = "certificate version 0.1\n" + "pusher " + ident.getRaw() + "\n"
            + "pushee test://localhost/repo.git\n" + "nonce " + nonce + "\n" + "\n"
            + "0000000000000000000000000000000000000000" + " deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
            + " refs/heads/master\n";
    PGPSignatureGenerator gen = new PGPSignatureGenerator(
            new BcPGPContentSignerBuilder(signingKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1));
    gen.init(PGPSignature.BINARY_DOCUMENT, signingKey.getPrivateKey());
    gen.update(payload.getBytes(UTF_8));
    PGPSignature sig = gen.generate();/*  ww w  .  j a v  a  2 s.  c  o m*/

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try (BCPGOutputStream out = new BCPGOutputStream(new ArmoredOutputStream(bout))) {
        sig.encode(out);
    }

    String cert = payload + new String(bout.toByteArray(), UTF_8);
    Reader reader = new InputStreamReader(new ByteArrayInputStream(cert.getBytes(UTF_8)));
    PushCertificateParser parser = new PushCertificateParser(tr.getRepository(), signedPushConfig);
    return parser.parse(reader);
}