Skip to content

Commit

Permalink
Allow SignatureKeyPair objects to create birationally equivalent Encr…
Browse files Browse the repository at this point in the history
…yptionKeyPair objects.
  • Loading branch information
paragonie-security committed Jan 26, 2018
1 parent bf6c1f6 commit e0c6053
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/SignatureKeyPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ public function __construct(Key ...$keys)
}
}

/**
* @return EncryptionKeyPair
* @throws InvalidKey
* @throws \TypeError
*/
public function getEncryptionKeyPair(): EncryptionKeyPair
{
return new EncryptionKeyPair(
$this->secretKey->getEncryptionSecretKey(),
$this->publicKey->getEncryptionPublicKey()
);
}

/**
* Set up our key pair
*
Expand Down
5 changes: 5 additions & 0 deletions test/unit/KeyPairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public function testFileStorage()
public function testMutation()
{
$sign_kp = KeyFactory::generateSignatureKeyPair();
$box_kp = $sign_kp->getEncryptionKeyPair();
$sign_sk = $sign_kp->getSecretKey();
$sign_pk = $sign_kp->getPublicKey();

Expand All @@ -245,6 +246,10 @@ public function testMutation()
Hex::encode($enc_pk->getRawKeyMaterial()),
Hex::encode($enc_sk->derivePublicKey()->getRawKeyMaterial())
);
$this->assertSame(
Hex::encode($enc_sk->getRawKeyMaterial()),
Hex::encode($box_kp->getSecretKey()->getRawKeyMaterial())
);
}

/**
Expand Down

0 comments on commit e0c6053

Please sign in to comment.