Package org.bouncycastle.util.test

Examples of org.bouncycastle.util.test.SimpleTestResult


        BigInteger   k1 = e1.calculateAgreement(pu2);
        BigInteger   k2 = e2.calculateAgreement(pu1);

        if (!k1.equals(k2))
        {
            return new SimpleTestResult(false, "basic " + size + " bit 2-way test failed");
        }

        return new SimpleTestResult(true, this.getName() + ": Okay");
    }
View Full Code Here


            hmac.update(m, 0, m.length);
            hmac.doFinal(resBuf, 0);

            if (!arraysEqual(resBuf, Hex.decode(digests[i])))
            {
                return new SimpleTestResult(false, getName() + ": Vector " + i + " failed");
            }
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

            byte[]  s = eng.generateSignature();

            if (!isEqualTo(s, sig))
            {
                return new SimpleTestResult(false, getName() + ": test " + id + " failed generation");
            }

            eng.init(false, pub);

            eng.update(msg, 0, msg.length);

            if (!eng.verifySignature(s))
            {
                return new SimpleTestResult(false, getName() + ": test " + id + " failed verification");
            }
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": test " + id + " failed - exception " + e.toString());
        }

        return new SimpleTestResult(true, getName() + ": test " + id + " Okay");
    }
View Full Code Here

                    failed++;
                }
            }
            catch (Exception e)
            {
                return new SimpleTestResult(
                    false,
                    getName() + ": loop test failed - exception " + e.toString());
            }
        }
       
        if (failed != 0)
        {
            return new SimpleTestResult(
                                false,
                                getName() + ": loop test failed - failures: " + failed);
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

        for (int i = 0; i != k1In.length; i++)
        {
            if (k1In[i] != k1Out[i])
            {
                return new SimpleTestResult(false, getName() + ": Failed "
                    + "got " + new String(Hex.encode(k1In))
                    + " expected " + new String(Hex.encode(k1Out)));
            }
        }

        DESParameters.setOddParity(k2In);

        for (int i = 0; i != k2In.length; i++)
        {
            if (k2In[i] != k2Out[i])
            {
                return new SimpleTestResult(false, getName() + ": Failed "
                    + "got " + new String(Hex.encode(k2In))
                    + " expected " + new String(Hex.encode(k2Out)));
            }
        }

        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

        digest.doFinal(resBuf, 0);

        resStr = new String(Hex.encode(resBuf));
        if (!resVec1.equals(resStr))
        {
            return new SimpleTestResult(false,
                "MD5 failing standard vector test 1"
                + System.getProperty("line.separator")
                + "    expected: " + resVec1
                + System.getProperty("line.separator")
                + "    got     : " + resStr);
        }

        //
        // test 2
        //
        byte[]  bytes = Hex.decode(testVec2);

        digest.update(bytes, 0, bytes.length);

        digest.doFinal(resBuf, 0);

        resStr = new String(Hex.encode(resBuf));
        if (!resVec2.equals(resStr))
        {
            return new SimpleTestResult(false,
                "MD5 failing standard vector test 2"
                + System.getProperty("line.separator")
                + "    expected: " + resVec2
                + System.getProperty("line.separator")
                + "    got     : " + resStr);
        }

        //
        // test 3
        //
        bytes = Hex.decode(testVec3);

        digest.update(bytes, 0, bytes.length);

        digest.doFinal(resBuf, 0);

        resStr = new String(Hex.encode(resBuf));
        if (!resVec3.equals(resStr))
        {
            return new SimpleTestResult(false,
                "MD5 failing standard vector test 3"
                + System.getProperty("line.separator")
                + "    expected: " + resVec3
                + System.getProperty("line.separator")
                + "    got     : " + resStr);
        }

        //
        // test 4
        //
        bytes = Hex.decode(testVec4);

        digest.update(bytes, 0, bytes.length);

        digest.doFinal(resBuf, 0);

        resStr = new String(Hex.encode(resBuf));
        if (!resVec4.equals(resStr))
        {
            return new SimpleTestResult(false,
                "MD5 failing standard vector test 4"
                + System.getProperty("line.separator")
                + "    expected: " + resVec4
                + System.getProperty("line.separator")
                + "    got     : " + resStr);
        }

        //
        // test 5
        //
        bytes = Hex.decode(testVec4);

        digest.update(bytes, 0, bytes.length/2);

        // clone the Digest
        Digest d = new MD5Digest((MD5Digest)digest);

        digest.update(bytes, bytes.length/2, bytes.length - bytes.length/2);
        digest.doFinal(resBuf, 0);

        resStr = new String(Hex.encode(resBuf));
        if (!resVec4.equals(resStr))
        {
            return new SimpleTestResult(false,
                "MD5 failing standard vector test 5"
                + System.getProperty("line.separator")
                + "    expected: " + resVec4
                + System.getProperty("line.separator")
                + "    got     : " + resStr);
        }

        d.update(bytes, bytes.length/2, bytes.length - bytes.length/2);
        d.doFinal(resBuf, 0);

        resStr = new String(Hex.encode(resBuf));
        if (!resVec4.equals(resStr))
        {
            return new SimpleTestResult(false,
                "MD5 failing standard vector test 5"
                + System.getProperty("line.separator")
                + "    expected: " + resVec4
                + System.getProperty("line.separator")
                + "    got     : " + resStr);
        }
        return new SimpleTestResult(true, getName() + ": Okay");
    }
View Full Code Here

            //
            // private key section
            //
            if (!c[0].getContentType().equals(PKCSObjectIdentifiers.data))
            {
                return new SimpleTestResult(false, getName() + ": failed comparison data test");
            }
           
            aIn = new ASN1InputStream(new ByteArrayInputStream(((ASN1OctetString)c[0].getContent()).getOctets()));
            ASN1Sequence    seq = (ASN1Sequence)aIn.readObject();
           
            SafeBag b = new SafeBag((ASN1Sequence)seq.getObjectAt(0));
            if (!b.getBagId().equals(PKCSObjectIdentifiers.pkcs8ShroudedKeyBag))
            {
                return new SimpleTestResult(false, getName() + ": failed comparison shroudedKeyBag test");
            }
           
            EncryptedPrivateKeyInfo encInfo = EncryptedPrivateKeyInfo.getInstance((ASN1Sequence)b.getBagValue());
           
            encInfo = new EncryptedPrivateKeyInfo(encInfo.getEncryptionAlgorithm(), encInfo.getEncryptedData());
           
            b = new SafeBag(PKCSObjectIdentifiers.pkcs8ShroudedKeyBag, encInfo.toASN1Object(), b.getBagAttributes());
           
            ByteArrayOutputStream abOut = new ByteArrayOutputStream();
            ASN1OutputStream      berOut = new ASN1OutputStream(abOut);
           
            berOut.writeObject(new DERSequence(b));
           
            c[0] = new ContentInfo(PKCSObjectIdentifiers.data, new BERConstructedOctetString(abOut.toByteArray()));
           
            //
            // certificates
            //
            if (!c[1].getContentType().equals(PKCSObjectIdentifiers.encryptedData))
            {
                return new SimpleTestResult(false, getName() + ": failed comparison encryptedData test");
            }
           
            EncryptedData   eData = EncryptedData.getInstance(c[1].getContent());
           
            c[1] = new ContentInfo(PKCSObjectIdentifiers.encryptedData, eData);
           
            //
            // create an octet stream represent the BER encoding of authSafe
            //
            authSafe = new AuthenticatedSafe(c);
           
            abOut = new ByteArrayOutputStream();
            berOut = new ASN1OutputStream(abOut);

            berOut.writeObject(authSafe);
           
            info = new ContentInfo(PKCSObjectIdentifiers.data, new BERConstructedOctetString(abOut.toByteArray()));
           
            mData = new MacData(new DigestInfo(algId, dInfo.getDigest()), salt, itCount);
           
            bag = new Pfx(info, mData);

            //
            // comparison test
            //
           
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            ASN1OutputStream        aOut = new ASN1OutputStream(bOut);
           
            aOut.writeObject(bag);
           
            if (!isSameAs(bOut.toByteArray(), pkcs12))
            {
                return new SimpleTestResult(false, getName() + ": failed comparison test");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": exception - " + e.toString(), e);
        }
    }
View Full Code Here

            ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(unsignedReq));
            OCSPRequest     req = OCSPRequest.getInstance(aIn.readObject());
           
            if (!isSameAs(req.getEncoded(), unsignedReq))
            {
                return new SimpleTestResult(false, getName() + ": OCSP unsigned request failed to re-encode");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": failed unsigned exception - " + e.toString(), e);
        }
    }
View Full Code Here

            ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(signedReq));
            OCSPRequest     req = OCSPRequest.getInstance(aIn.readObject());
           
            if (!isSameAs(req.getEncoded(), signedReq))
            {
                return new SimpleTestResult(false, getName() + ": OCSP signed request failed to re-encode");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": failed signed exception - " + e.toString(), e);
        }
    }
View Full Code Here

           
            resp = new OCSPResponse(resp.getResponseStatus(), new ResponseBytes(rBytes.getResponseType(), new DEROctetString(bResp.getEncoded())));
           
            if (!isSameAs(resp.getEncoded(), response))
            {
                return new SimpleTestResult(false, getName() + ": OCSP response failed to re-encode");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        catch (Exception e)
        {
            return new SimpleTestResult(false, getName() + ": failed response exception - " + e.toString(), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.util.test.SimpleTestResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.