Search in sources :

Example 1 with NonNull

use of org.checkerframework.checker.nullness.qual.NonNull in project checker-framework by typetools.

the class NonNullMapValue method process_unmatched_procedure_entries.

public static void process_unmatched_procedure_entries() {
    HashMap<Integer, Date> call_hashmap = new HashMap<Integer, Date>();
    for (Integer i : call_hashmap.keySet()) {
        @NonNull Date d = call_hashmap.get(i);
    }
    Set<@KeyFor("call_hashmap") Integer> keys = call_hashmap.keySet();
    for (Integer i : keys) {
        @NonNull Date d = call_hashmap.get(i);
    }
    Set<@KeyFor("call_hashmap") Integer> keys_sorted = new TreeSet<@KeyFor("call_hashmap") Integer>(call_hashmap.keySet());
    for (Integer i : keys_sorted) {
        @NonNull Date d = call_hashmap.get(i);
    }
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) NonNull(org.checkerframework.checker.nullness.qual.NonNull) KeyFor(org.checkerframework.checker.nullness.qual.KeyFor) Date(java.util.Date)

Example 2 with NonNull

use of org.checkerframework.checker.nullness.qual.NonNull in project universa by UniversaBlockchain.

the class RSAOAEPPublicKey method checkSignature.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException {
    if (state == null) {
        throw new IllegalStateException();
    } else {
        final Digest primaryDigest = hashType.makeDigest();
        if (saltLength == MAX_SALT_LENGTH) {
            saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize());
        }
        if (saltLength < 0) {
            throw new RuntimeException(String.format("Incorrect salt length %s", saltLength));
        }
        final Signer signatureChecker = new PSSSigner(RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength);
        signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng));
        boolean done = false;
        while (!done) {
            int availableBytes = input.available();
            if (availableBytes <= 0) {
                done = true;
            } else {
                byte[] buffer = new byte[availableBytes];
                int howManyBytesRead = input.read(buffer);
                if (howManyBytesRead <= 0) {
                    done = true;
                } else {
                    signatureChecker.update(buffer, 0, howManyBytesRead);
                }
            }
        }
        return signatureChecker.verifySignature(signature);
    }
}
Also used : PSSSigner(org.spongycastle.crypto.signers.PSSSigner) Signer(org.spongycastle.crypto.Signer) Digest(org.spongycastle.crypto.Digest) SHA1Digest(org.spongycastle.crypto.digests.SHA1Digest) PSSSigner(org.spongycastle.crypto.signers.PSSSigner) ParametersWithRandom(org.spongycastle.crypto.params.ParametersWithRandom) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 3 with NonNull

use of org.checkerframework.checker.nullness.qual.NonNull in project universa by UniversaBlockchain.

the class Capsule method prepareSigners.

@NonNull
private HashMap<String, AbstractKey> prepareSigners(Binder payload) {
    HashMap<String, AbstractKey> sigIds = new HashMap<>();
    if (signers != null && !signers.isEmpty()) {
        ArrayList<Binder> s = payload.set("signers", new ArrayList<>());
        int i = 0;
        for (Binder b : signers.values()) {
            final String id = b.getStringOrThrow("id");
            final AbstractKey key = (AbstractKey) b.get("key");
            sigIds.put(id, key);
            Binder signerData = new Binder("id", id, "key", key.getPublicKey().pack(), "data", b.getBinder("data"));
            s.add(signerData);
        }
    }
    return sigIds;
}
Also used : Binder(net.sergeych.tools.Binder) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 4 with NonNull

use of org.checkerframework.checker.nullness.qual.NonNull in project universa by UniversaBlockchain.

the class Capsule method preparePayload.

@NonNull
private Binder preparePayload() throws EncryptionError {
    Binder payload = new Binder();
    // Private data
    if (hasPrivate()) {
        if (encryptingKeys == null || encryptingKeys.isEmpty()) {
            throw new IllegalStateException("missing encryption keys");
        }
        SymmetricKey mainKey = new SymmetricKey();
        byte[] packedMainKey = mainKey.pack();
        Binder data = payload.set("private", new Binder());
        ArrayList keys = data.set("keys", new ArrayList<Binder>());
        for (AbstractKey k : encryptingKeys) {
            if (k == null)
                throw new IllegalStateException("null is forbidden in encryption keys");
            Binder b = new Binder("keyInfo", k.packedInfo(), "key", k.encrypt(packedMainKey));
            keys.add(b);
        }
        // Private data are packed with random filler. The way it is donne
        // fill will simply not read
        byte[] packedPrivate = Boss.dumpToArray(privateData, CTRTransformer.randomBytes(0, 117));
        data.put("data", mainKey.etaEncrypt(packedPrivate));
    }
    // public data
    if (hasPublic()) {
        payload.put("public", publicData);
    }
    payload.put("type", "capsule");
    return payload;
}
Also used : Binder(net.sergeych.tools.Binder) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 5 with NonNull

use of org.checkerframework.checker.nullness.qual.NonNull in project universa by UniversaBlockchain.

the class Capsule method unpackPayload.

@NonNull
private Binder unpackPayload(byte[] packedCoffer, boolean allowPartiallySigned) throws EncryptionError {
    signed = false;
    Binder outer = Boss.unpack(packedCoffer);
    Collection<Binder> signatures = outer.getBinders("signatures");
    final byte[] source = outer.getBinary("content");
    Binder payload = Boss.unpack(source);
    if (!payload.get("type").equals("capsule"))
        throw new FormatException("not capsule/unknown type");
    checkSignatures(source, signatures, payload, allowPartiallySigned);
    publicData = payload.getBinder("public");
    return payload;
}
Also used : Binder(net.sergeych.tools.Binder) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

NonNull (org.checkerframework.checker.nullness.qual.NonNull)9 Binder (net.sergeych.tools.Binder)4 HashMap (java.util.HashMap)2 StrBuilder (org.apache.commons.lang3.text.StrBuilder)2 Decimal (com.icodici.universa.Decimal)1 Contract (com.icodici.universa.contract.Contract)1 Permission (com.icodici.universa.contract.permissions.Permission)1 SplitJoinPermission (com.icodici.universa.contract.permissions.SplitJoinPermission)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1