public void testOverwrite()
        {
            PibMemory       pibImpl   = new PibMemory();
            PibIdentityImpl identity1 = new PibIdentityImpl(fixture.id1, pibImpl,
                                                            true);

            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            Assert.AssertTrue(identity1.getKey(fixture.id1Key1Name).getPublicKey()
                              .equals(fixture.id1Key1));

            // Overwriting the key should work.
            identity1.addKey(fixture.id1Key2.buf(), fixture.id1Key1Name);
            Assert.AssertTrue(identity1.getKey(fixture.id1Key1Name).getPublicKey()
                              .equals(fixture.id1Key2));
        }
        public void testErrors()
        {
            PibMemory pibImpl = new PibMemory();

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

            PibIdentityImpl identity1 = new PibIdentityImpl(fixture.id1, pibImpl,
                                                            true);

            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            try {
                identity1.addKey(fixture.id2Key1.buf(), fixture.id2Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_1) {
            } catch (Exception ex_2) {
                Assert.Fail("Did not throw the expected exception");
            }

            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            try {
                identity1.removeKey(fixture.id2Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_3) {
            } catch (Exception ex_4) {
                Assert.Fail("Did not throw the expected exception");
            }

            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            try {
                identity1.getKey(fixture.id2Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_5) {
            } catch (Exception ex_6) {
                Assert.Fail("Did not throw the expected exception");
            }

            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            try {
                identity1.setDefaultKey(fixture.id2Key1.buf(), fixture.id2Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_7) {
            } catch (Exception ex_8) {
                Assert.Fail("Did not throw the expected exception");
            }

            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            try {
                identity1.setDefaultKey(fixture.id2Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (ArgumentException ex_9) {
            } catch (Exception ex_10) {
                Assert.Fail("Did not throw the expected exception");
            }
        }
        public void testKeyOperation()
        {
            PibMemory       pibImpl   = new PibMemory();
            PibIdentityImpl identity1 = new PibIdentityImpl(fixture.id1, pibImpl,
                                                            true);

            try {
                new PibIdentityImpl(fixture.id1, pibImpl, false);
            } catch (Exception ex) {
                Assert.Fail("Unexpected exception: " + ex.Message);
            }

            // The identity should not have any key.
            Assert.AssertEquals(0, identity1.getKeys_().size());

            // Getting non-existing key should throw Pib.Error.
            try {
                identity1.getKey(fixture.id1Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_0) {
            } catch (Exception ex_1) {
                Assert.Fail("Did not throw the expected exception");
            }
            // Getting the default key should throw Pib.Error.
            try {
                identity1.getDefaultKey();
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_2) {
            } catch (Exception ex_3) {
                Assert.Fail("Did not throw the expected exception");
            }
            // Setting a non-existing key as the default key should throw Pib.Error.
            try {
                identity1.setDefaultKey(fixture.id1Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_4) {
            } catch (Exception ex_5) {
                Assert.Fail("Did not throw the expected exception");
            }

            // Add a key.
            identity1.addKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            try {
                identity1.getKey(fixture.id1Key1Name);
            } catch (Exception ex_6) {
                Assert.Fail("Unexpected exception: " + ex_6.Message);
            }

            // A new key should become the default key when there is no default.
            try {
                identity1.getDefaultKey();
            } catch (Exception ex_7) {
                Assert.Fail("Unexpected exception: " + ex_7.Message);
            }
            PibKey defaultKey0 = identity1.getDefaultKey();

            Assert.AssertTrue(fixture.id1Key1Name.equals(defaultKey0.getName()));
            Assert.AssertTrue(defaultKey0.getPublicKey().equals(fixture.id1Key1));

            // Remove a key.
            identity1.removeKey(fixture.id1Key1Name);
            try {
                identity1.setDefaultKey(fixture.id1Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_8) {
            } catch (Exception ex_9) {
                Assert.Fail("Did not throw the expected exception");
            }

            try {
                identity1.getDefaultKey();
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_10) {
            } catch (Exception ex_11) {
                Assert.Fail("Did not throw the expected exception");
            }

            // Set the default key directly.
            try {
                identity1.setDefaultKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            } catch (Exception ex_12) {
                Assert.Fail("Unexpected exception: " + ex_12.Message);
            }
            try {
                identity1.getDefaultKey();
            } catch (Exception ex_13) {
                Assert.Fail("Unexpected exception: " + ex_13.Message);
            }
            try {
                identity1.getKey(fixture.id1Key1Name);
            } catch (Exception ex_14) {
                Assert.Fail("Unexpected exception: " + ex_14.Message);
            }

            // Check for a default key.
            PibKey defaultKey1 = identity1.getDefaultKey();

            Assert.AssertTrue(fixture.id1Key1Name.equals(defaultKey1.getName()));
            Assert.AssertTrue(defaultKey1.getPublicKey().equals(fixture.id1Key1));

            // Add another key.
            identity1.addKey(fixture.id1Key2.buf(), fixture.id1Key2Name);
            Assert.AssertEquals(2, identity1.getKeys_().size());

            // Set the default key using a name.
            try {
                identity1.setDefaultKey(fixture.id1Key2Name);
            } catch (Exception ex_15) {
                Assert.Fail("Unexpected exception: " + ex_15.Message);
            }
            try {
                identity1.getDefaultKey();
            } catch (Exception ex_16) {
                Assert.Fail("Unexpected exception: " + ex_16.Message);
            }
            PibKey defaultKey2 = identity1.getDefaultKey();

            Assert.AssertTrue(fixture.id1Key2Name.equals(defaultKey2.getName()));
            Assert.AssertTrue(defaultKey2.getPublicKey().equals(fixture.id1Key2));

            // Remove a key.
            identity1.removeKey(fixture.id1Key1Name);
            try {
                identity1.getKey(fixture.id1Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_17) {
            } catch (Exception ex_18) {
                Assert.Fail("Did not throw the expected exception");
            }

            Assert.AssertEquals(1, identity1.getKeys_().size());

            // Seting the default key directly again should change the default.
            try {
                identity1.setDefaultKey(fixture.id1Key1.buf(), fixture.id1Key1Name);
            } catch (Exception ex_19) {
                Assert.Fail("Unexpected exception: " + ex_19.Message);
            }
            PibKey defaultKey3 = identity1.getDefaultKey();

            Assert.AssertTrue(fixture.id1Key1Name.equals(defaultKey3.getName()));
            Assert.AssertTrue(defaultKey3.getPublicKey().equals(fixture.id1Key1));
            Assert.AssertEquals(2, identity1.getKeys_().size());

            // Remove all keys.
            identity1.removeKey(fixture.id1Key1Name);
            try {
                identity1.getKey(fixture.id1Key1Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_20) {
            } catch (Exception ex_21) {
                Assert.Fail("Did not throw the expected exception");
            }

            Assert.AssertEquals(1, identity1.getKeys_().size());
            identity1.removeKey(fixture.id1Key2Name);
            try {
                identity1.getKey(fixture.id1Key2Name);
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_22) {
            } catch (Exception ex_23) {
                Assert.Fail("Did not throw the expected exception");
            }

            Assert.AssertEquals(0, identity1.getKeys_().size());
            try {
                identity1.getDefaultKey();
                Assert.Fail("Did not throw the expected exception");
            } catch (Pib.Error ex_24) {
            } catch (Exception ex_25) {
                Assert.Fail("Did not throw the expected exception");
            }
        }