Пример #1
0
        public void testOverwrite()
        {
            PibMemory pibImpl = new PibMemory();

            try {
                new PibKeyImpl(fixture.id1Key1Name, pibImpl);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex) {
            } catch (Exception ex_0) {
                Assert.Fail("Did not throw the expected exception");
            }

            new PibKeyImpl(fixture.id1Key1Name, fixture.id1Key1.buf(), pibImpl);
            PibKeyImpl key1 = new PibKeyImpl(fixture.id1Key1Name, pibImpl);

            // Overwriting the key should work.
            new PibKeyImpl(fixture.id1Key1Name, fixture.id1Key2.buf(), pibImpl);
            PibKeyImpl key2 = new PibKeyImpl(fixture.id1Key1Name, pibImpl);

            // key1 should have cached the original public key.
            Assert.AssertTrue(!key1.getPublicKey().equals(key2.getPublicKey()));
            Assert.AssertTrue(key2.getPublicKey().equals(fixture.id1Key2));

            key1.addCertificate(fixture.id1Key1Cert1);
            // Use the wire encoding to check equivalence.
            Assert.AssertTrue(key1.getCertificate(fixture.id1Key1Cert1.getName())
                              .wireEncode().equals(fixture.id1Key1Cert1.wireEncode()));

            CertificateV2 otherCert = new CertificateV2(fixture.id1Key1Cert1);

            ((Sha256WithRsaSignature)otherCert.getSignature()).getValidityPeriod()
            .setPeriod(net.named_data.jndn.util.Common.getNowMilliseconds(),
                       net.named_data.jndn.util.Common.getNowMilliseconds() + 1000);
            // Don't bother resigning so we don't have to load a private key.

            Assert.AssertTrue(fixture.id1Key1Cert1.getName().equals(otherCert.getName()));
            Assert.AssertTrue(otherCert.getContent().equals(
                                  fixture.id1Key1Cert1.getContent()));
            Assert.AssertFalse(otherCert.wireEncode().equals(
                                   fixture.id1Key1Cert1.wireEncode()));

            key1.addCertificate(otherCert);

            Assert.AssertTrue(key1.getCertificate(fixture.id1Key1Cert1.getName())
                              .wireEncode().equals(otherCert.wireEncode()));
        }
Пример #2
0
        public void testBasic()
        {
            PibMemory  pibImpl = new PibMemory();
            PibKeyImpl key11   = new PibKeyImpl(fixture.id1Key1Name,
                                                fixture.id1Key1.buf(), pibImpl);

            Assert.AssertTrue(fixture.id1Key1Name.equals(key11.getName()));
            Assert.AssertTrue(fixture.id1.equals(key11.getIdentityName()));
            Assert.AssertEquals(net.named_data.jndn.security.KeyType.RSA, key11.getKeyType());
            Assert.AssertTrue(key11.getPublicKey().equals(fixture.id1Key1));

            PibKeyImpl key11FromBackend = new PibKeyImpl(fixture.id1Key1Name,
                                                         pibImpl);

            Assert.AssertTrue(fixture.id1Key1Name.equals(key11FromBackend.getName()));
            Assert.AssertTrue(fixture.id1.equals(key11FromBackend.getIdentityName()));
            Assert.AssertEquals(net.named_data.jndn.security.KeyType.RSA, key11FromBackend.getKeyType());
            Assert.AssertTrue(key11FromBackend.getPublicKey().equals(fixture.id1Key1));
        }