Skip to content

Commit

Permalink
Add PgpSignatureProcessorFactory class and Bc implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Apr 3, 2024
1 parent 787fda7 commit 77d1ef0
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 Paul Schaub
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm.signature;

import org.bouncycastle.openpgp.PGPPrivateKey;

/**
* Implementation of the {@link PgpSignatureProcessorFactory} that uses Bouncy Castle directly for signing.
*/
public class BcPgpSignatureProcessorFactory extends PgpSignatureProcessorFactory {

private final PGPPrivateKey privateKey;
private final int hashAlgorithm;

/**
* Create a new factory.
*
* @param privateKey private signing key
* @param hashAlgorithm OpenPgp hash algorithm ID of the digest algorithm used for signing
*/
public BcPgpSignatureProcessorFactory(PGPPrivateKey privateKey, int hashAlgorithm) {
this.privateKey = privateKey;
this.hashAlgorithm = hashAlgorithm;
}

@Override
public SignatureProcessor createHeaderSignatureProcessor() {
return new RsaHeaderSignatureProcessor(privateKey, hashAlgorithm);
}

@Override
public SignatureProcessor createSignatureProcessor() {
return new RsaSignatureProcessor(privateKey, hashAlgorithm);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Paul Schaub
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm.signature;

/**
* Factory for creating OpenPGP signing-related {@link SignatureProcessor} instances.
* By default, packager will use {@link BcPgpSignatureProcessorFactory}.
* TODO: Use Dependency Injection to allow for dynamic replacing of the factory instance.
*/
public abstract class PgpSignatureProcessorFactory {

/**
* Create a {@link SignatureProcessor} for signing the header.
*
* @return header signature processor
*/
public abstract SignatureProcessor createHeaderSignatureProcessor();

/**
* Create a {@link SignatureProcessor} for signing both header and data.
*
* @return signature processor
*/
public abstract SignatureProcessor createSignatureProcessor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
import org.eclipse.packager.rpm.info.RpmInformation;
import org.eclipse.packager.rpm.info.RpmInformation.Changelog;
import org.eclipse.packager.rpm.info.RpmInformation.Dependency;
import org.eclipse.packager.security.pgp.BcPgpSignerFactory;
import org.eclipse.packager.security.pgp.PgpSignerFactory;
import org.eclipse.packager.security.pgp.BcPgpSignerCreator;
import org.eclipse.packager.security.pgp.PgpSignerCreator;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -440,7 +440,7 @@ public Builder setSigning(final Function<OutputStream, OutputStream> signingStre
return this;
}

public Builder setSigning(PgpSignerFactory signingFactory) {
public Builder setSigning(PgpSignerCreator signingFactory) {
return setSigning(signingFactory.createSigningStream());
}

Expand All @@ -456,7 +456,7 @@ public Builder setSigning(final PGPPrivateKey privateKey, final HashAlgorithm ha

@Deprecated
public Builder setSigning(final PGPPrivateKey privateKey, final int digestAlgorithm) {
return setSigning(new BcPgpSignerFactory(privateKey, digestAlgorithm, false));
return setSigning(new BcPgpSignerCreator(privateKey, digestAlgorithm, false));
}

public RepositoryCreator build() {
Expand Down

0 comments on commit 77d1ef0

Please sign in to comment.