Skip to content

Commit

Permalink
Refactor keytype related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Dec 8, 2020
1 parent 4550425 commit 3c88bdd
Show file tree
Hide file tree
Showing 33 changed files with 340 additions and 151 deletions.
Expand Up @@ -53,8 +53,8 @@
import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.curve.EllipticCurve;
import org.pgpainless.key.generation.type.length.RsaLength;
import org.pgpainless.key.generation.type.EllipticCurve;
import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.util.UserId;
import org.pgpainless.provider.ProviderFactory;
import org.pgpainless.util.Passphrase;
Expand Down

This file was deleted.

Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type.curve;
package org.pgpainless.key.generation.type;

import javax.annotation.Nonnull;

Expand Down
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type.length;
package org.pgpainless.key.generation.type;

public interface KeyLength {

Expand Down
Expand Up @@ -18,8 +18,10 @@
import java.security.spec.AlgorithmParameterSpec;

import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.curve.EllipticCurve;
import org.pgpainless.key.generation.type.length.RsaLength;
import org.pgpainless.key.generation.type.ecdh.ECDH;
import org.pgpainless.key.generation.type.ecdsa.ECDSA;
import org.pgpainless.key.generation.type.rsa.RsaLength;
import org.pgpainless.key.generation.type.rsa.RSA;

public interface KeyType {

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,5 +1,5 @@
/*
* Copyright 2018 Paul Schaub.
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type;
package org.pgpainless.key.generation.type.ecdh;

import javax.annotation.Nonnull;
import java.security.spec.AlgorithmParameterSpec;

import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.curve.EllipticCurve;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.EllipticCurve;

public class ECDH implements KeyType {
public final class ECDH implements KeyType {

private final EllipticCurve curve;

ECDH(EllipticCurve curve) {
private ECDH(EllipticCurve curve) {
this.curve = curve;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Paul Schaub.
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,6 @@
* limitations under the License.
*/
/**
* Classes related to elliptic curve cryptography.
* Classes related to ECDH.
*/
package org.pgpainless.key.generation.type.curve;
package org.pgpainless.key.generation.type.ecdh;
Expand Up @@ -13,18 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type;
package org.pgpainless.key.generation.type.ecdsa;


import java.security.spec.AlgorithmParameterSpec;
import javax.annotation.Nonnull;

import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.curve.EllipticCurve;
import org.pgpainless.key.generation.type.EllipticCurve;
import org.pgpainless.key.generation.type.KeyType;

public class ECDSA extends ECDH {
public final class ECDSA implements KeyType {

ECDSA(@Nonnull EllipticCurve curve) {
super(curve);
private final EllipticCurve curve;

private ECDSA(@Nonnull EllipticCurve curve) {
this.curve = curve;
}

public static ECDSA fromCurve(@Nonnull EllipticCurve curve) {
Expand All @@ -40,4 +45,9 @@ public String getName() {
public PublicKeyAlgorithm getAlgorithm() {
return PublicKeyAlgorithm.ECDSA;
}

@Override
public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName());
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Classes related to ECDSA.
*/
package org.pgpainless.key.generation.type.ecdsa;
@@ -0,0 +1,50 @@
/*
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type.eddsa;

import java.security.spec.AlgorithmParameterSpec;

import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.KeyType;

public final class EdDSA implements KeyType {

private final EdDSACurve curve;

private EdDSA(EdDSACurve curve) {
this.curve = curve;
}

public static EdDSA fromCurve(EdDSACurve curve) {
return new EdDSA(curve);
}

@Override
public String getName() {
return "EdDSA";
}

@Override
public PublicKeyAlgorithm getAlgorithm() {
return PublicKeyAlgorithm.EDDSA;
}

@Override
public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName());
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type.eddsa;

import javax.annotation.Nonnull;

public enum EdDSACurve {
_Ed25519("ed25519"),
;

final String name;

EdDSACurve(@Nonnull String curveName) {
this.name = curveName;
}

public String getName() {
return name;
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Classes related to EdDSA.
*/
package org.pgpainless.key.generation.type.eddsa;
Expand Up @@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type.length;
package org.pgpainless.key.generation.type.elgamal;

import java.math.BigInteger;

import org.pgpainless.key.generation.type.KeyLength;

/**
* The following primes are taken from RFC-3526.
*
Expand Down
Expand Up @@ -13,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation.type;
package org.pgpainless.key.generation.type.elgamal;

import javax.annotation.Nonnull;

import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.length.ElGamalLength;

public class ElGamal_ENCRYPT extends ElGamal_GENERAL {

Expand Down

0 comments on commit 3c88bdd

Please sign in to comment.