Skip to content

Commit 181e5f3

Browse files
authored
Merge pull request #267 from mjrider/remove-loadFromRawBytesForTestingPurposesOnlyInsecure
Remove Key::loadFromRawBytesForTestingPurposesOnlyInsecure
2 parents 174673e + ec9d098 commit 181e5f3

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/Key.php

-13
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,4 @@ private function __construct($bytes)
8181
$this->key_bytes = $bytes;
8282
}
8383

84-
/**
85-
* INTERNAL USE ONLY: Constructs a Key object from a string of raw bytes.
86-
*
87-
* @param $bytes
88-
*
89-
* @return \Defuse\Crypto\Key
90-
*
91-
* @internal
92-
*/
93-
public static function loadFromRawBytesForTestingPurposesOnlyInsecure($bytes)
94-
{
95-
return new Key($bytes);
96-
}
9784
}

test/unit/BackwardsCompatibilityTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77
class BackwardsCompatibilityTest extends PHPUnit_Framework_TestCase
88
{
9+
10+
/* helper function to create a key with raw bytes */
11+
public function keyHelper($rawkey) {
12+
$key = Key::createNewRandomKey();
13+
$func = function ($bytes) {
14+
$this->key_bytes = $bytes;
15+
};
16+
$helper = $func->bindTo($key,$key);
17+
$helper($rawkey);
18+
return $key;
19+
}
20+
921
/**
1022
* @expectedException \Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException
1123
* @expectedExceptionMessage invalid hex encoding
@@ -25,7 +37,7 @@ public function testDecryptLegacyWithWrongMethodStraightUpHex()
2537
/* Make it try to parse the binary as hex. */
2638
$plain = Crypto::decrypt(
2739
$cipher,
28-
Key::loadFromRawBytesForTestingPurposesOnlyInsecure(
40+
$this->keyHelper (
2941
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" .
3042
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
3143
),
@@ -52,7 +64,7 @@ public function testDecryptLegacyWithWrongMethodStraightUpBinary()
5264
/* This time, treat the binary as binary. */
5365
$plain = Crypto::decrypt(
5466
$cipher,
55-
Key::loadFromRawBytesForTestingPurposesOnlyInsecure(
67+
$this->keyHelper (
5668
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" .
5769
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
5870
),

0 commit comments

Comments
 (0)