Exemple #1
0
    def test_save_election_public_key(self):
        # Arrange
        guardian = Guardian(SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER,
                            NUMBER_OF_GUARDIANS, QUORUM)
        other_guardian = Guardian(RECIPIENT_GUARDIAN_ID,
                                  RECIPIENT_SEQUENCE_ORDER,
                                  NUMBER_OF_GUARDIANS, QUORUM)
        public_key = other_guardian.share_election_public_key()

        # Act
        guardian.save_election_public_key(public_key)

        # Assert
        self.assertTrue(guardian.all_election_public_keys_received())
Exemple #2
0
    def test_publish_joint_key(self):
        # Arrange
        # Round 1
        guardian = Guardian(
            SENDER_GUARDIAN_ID, SENDER_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        other_guardian = Guardian(
            RECIPIENT_GUARDIAN_ID, RECIPIENT_SEQUENCE_ORDER, NUMBER_OF_GUARDIANS, QUORUM
        )
        guardian.save_guardian_public_keys(other_guardian.share_public_keys())
        other_guardian.save_guardian_public_keys(guardian.share_public_keys())

        # Round 2
        guardian.generate_election_partial_key_backups(identity_auxiliary_encrypt)
        key_backup = guardian.share_election_partial_key_backup(RECIPIENT_GUARDIAN_ID)
        other_guardian.save_election_partial_key_backup(key_backup)
        verification = other_guardian.verify_election_partial_key_backup(
            SENDER_GUARDIAN_ID, identity_auxiliary_decrypt
        )

        # Act
        joint_key = guardian.publish_joint_key()

        # Assert
        self.assertIsNone(joint_key)

        # Act
        guardian.save_election_public_key(other_guardian.share_election_public_key())
        joint_key = guardian.publish_joint_key()

        # Assert
        self.assertIsNone(joint_key)

        # Act
        guardian.save_election_partial_key_verification(verification)
        joint_key = guardian.publish_joint_key()

        # Assert
        self.assertIsNotNone(joint_key)
        self.assertNotEqual(joint_key, guardian.share_election_public_key().key)