<commit_before>/*
 * Copyright 2015 <NAME>. <<EMAIL>>
 *
 * 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 us.eharning.atomun.core.ec.internal;

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequenceGenerator;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.signers.ECDSASigner;
import us.eharning.atomun.core.ValidationException;
import us.eharning.atomun.core.ec.ECKey;
import us.eharning.atomun.core.encoding.Base58;
import us.eharning.atomun.core.utility.Hash;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

/**
 * ECKey implementation wrapping a full keypair using BouncyCastle.
 */
@Immutable
public class BouncyCastleECKeyPair extends BouncyCastleECPublicKey {
    /**
     * Canonicalization flag - default true, but can be disabled in unit tests.
     */
    static boolean CANONICALIZE = true;
    private static final BigInteger HALF_CURVE_ORDER = curve.getN().shiftRight(1);

    @Nonnull
    private final BigInteger privateExponent;

    /**
     * Construct a new EC keypair given the private exponent and whether or not to use compressed point form.
     *
     * @param privateExponent
     *         value defining the private key.
     * @param compressed
     *         whether or not to use compressed point form.
     */
    public BouncyCastleECKeyPair(@Nonnull BigInteger privateExponent, boolean compressed) {
        this(privateExponent, curve.getG().multiply(privateExponent).getEncoded(compressed), compressed);
    }
<commit_msg>BouncyCastleECKeyPair: disable FB checks on the CANONICALIZE check as it is in place (temporarily)<commit_after>/*
 * Copyright 2015 <NAME>. <<EMAIL>>
 *
 * 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 us.eharning.atomun.core.ec.internal;

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequenceGenerator;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.signers.ECDSASigner;
import us.eharning.atomun.core.ValidationException;
import us.eharning.atomun.core.ec.ECKey;
import us.eharning.atomun.core.encoding.Base58;
import us.eharning.atomun.core.utility.Hash;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

/**
 * ECKey implementation wrapping a full keypair using BouncyCastle.
 */
@Immutable
public class BouncyCastleECKeyPair extends BouncyCastleECPublicKey {
    /**
     * Canonicalization flag - default true, but can be disabled in unit tests.
     * @TODO: Drop this in place of an alternate signing mechanism that can handle this.
     */
    @SuppressFBWarnings("JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS")
    static boolean CANONICALIZE = true;
    private static final BigInteger HALF_CURVE_ORDER = curve.getN().shiftRight(1);

    @Nonnull
    private final BigInteger privateExponent;

    /**
     * Construct a new EC keypair given the private exponent and whether or not to use compressed point form.
     *
     * @param privateExponent
     *         value defining the private key.
     * @param compressed
     *         whether or not to use compressed point form.
     */
    public BouncyCastleECKeyPair(@Nonnull BigInteger privateExponent, boolean compressed) {
        this(privateExponent, curve.getG().multiply(privateExponent).getEncoded(compressed), compressed);
    }

{'fraction_non_alphanumeric': 0.08264765039312488, 'fraction_numerical': 0.006216858657889925, 'mean_word_length': 4.421209117938553, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5454297', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1566, 'n_words': 452}