Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/SubKeyTest.php @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
| author | Charlie Root |
|---|---|
| date | Thu, 04 Jan 2018 15:50:29 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1e000243b222 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ | |
| 4 | |
| 5 /** | |
| 6 * Sub-key class test cases for the Crypt_GPG package. | |
| 7 * | |
| 8 * These tests require the PHPUnit 3.6 or greater package to be installed. | |
| 9 * PHPUnit is installable using PEAR. See the | |
| 10 * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual} | |
| 11 * for detailed installation instructions. | |
| 12 * | |
| 13 * To run these tests, use: | |
| 14 * <code> | |
| 15 * $ phpunit SubKeyTestCase | |
| 16 * </code> | |
| 17 * | |
| 18 * LICENSE: | |
| 19 * | |
| 20 * This library is free software; you can redistribute it and/or modify | |
| 21 * it under the terms of the GNU Lesser General Public License as | |
| 22 * published by the Free Software Foundation; either version 2.1 of the | |
| 23 * License, or (at your option) any later version. | |
| 24 * | |
| 25 * This library is distributed in the hope that it will be useful, | |
| 26 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 28 * Lesser General Public License for more details. | |
| 29 * | |
| 30 * You should have received a copy of the GNU Lesser General Public | |
| 31 * License along with this library; if not, see | |
| 32 * <http://www.gnu.org/licenses/> | |
| 33 * | |
| 34 * @category Encryption | |
| 35 * @package Crypt_GPG | |
| 36 * @author Michael Gauthier <mike@silverorange.com> | |
| 37 * @copyright 2008-2010 silverorange | |
| 38 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | |
| 39 * @version CVS: $Id$ | |
| 40 * @link http://pear.php.net/package/Crypt_GPG | |
| 41 */ | |
| 42 | |
| 43 /** | |
| 44 * Base test case. | |
| 45 */ | |
| 46 require_once 'TestCase.php'; | |
| 47 | |
| 48 /** | |
| 49 * Sub-key class. | |
| 50 */ | |
| 51 require_once 'Crypt/GPG/SubKey.php'; | |
| 52 | |
| 53 /** | |
| 54 * Sub-key class tests for Crypt_GPG. | |
| 55 * | |
| 56 * @category Encryption | |
| 57 * @package Crypt_GPG | |
| 58 * @author Michael Gauthier <mike@silverorange.com> | |
| 59 * @copyright 2008-2010 silverorange | |
| 60 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 | |
| 61 * @link http://pear.php.net/package/Crypt_GPG | |
| 62 */ | |
| 63 class SubKeyTestCase extends Crypt_GPG_TestCase | |
| 64 { | |
| 65 // construct | |
| 66 // {{{ testConstructFromString() | |
| 67 | |
| 68 /** | |
| 69 * @group construct | |
| 70 */ | |
| 71 public function testConstructFromString() | |
| 72 { | |
| 73 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 74 'id' => '8C37DBD2A01B7976', | |
| 75 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 76 'length' => 2048, | |
| 77 'creation' => 1221528655, | |
| 78 'expiration' => 0, | |
| 79 'canSign' => false, | |
| 80 'canEncrypt' => true, | |
| 81 'isRevoked' => true | |
| 82 )); | |
| 83 | |
| 84 $string = 'sub:r:2048:16:8C37DBD2A01B7976:1221528655::::::e:'; | |
| 85 $subKey = new Crypt_GPG_SubKey($string); | |
| 86 | |
| 87 $this->assertEquals($expectedSubKey, $subKey); | |
| 88 } | |
| 89 | |
| 90 // }}} | |
| 91 // {{{ testConstructFromSubKey() | |
| 92 | |
| 93 /** | |
| 94 * @group construct | |
| 95 */ | |
| 96 public function testConstructFromSubKey() | |
| 97 { | |
| 98 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 99 'id' => '8C37DBD2A01B7976', | |
| 100 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 101 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 102 'length' => 2048, | |
| 103 'creation' => 1221785858, | |
| 104 'expiration' => 1421785858, | |
| 105 'canSign' => false, | |
| 106 'canEncrypt' => true, | |
| 107 'hasPrivate' => true, | |
| 108 'isRevoked' => true | |
| 109 )); | |
| 110 | |
| 111 $subKey = new Crypt_GPG_SubKey($expectedSubKey); | |
| 112 | |
| 113 $this->assertEquals($expectedSubKey, $subKey); | |
| 114 } | |
| 115 | |
| 116 // }}} | |
| 117 // {{{ testConstructFromArray() | |
| 118 | |
| 119 /** | |
| 120 * @group construct | |
| 121 */ | |
| 122 public function testConstructFromArray() | |
| 123 { | |
| 124 $subKey = new Crypt_GPG_SubKey(array( | |
| 125 'id' => '8C37DBD2A01B7976', | |
| 126 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 127 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 128 'length' => 2048, | |
| 129 'creation' => 1221785858, | |
| 130 'expiration' => 1421785858, | |
| 131 'canSign' => false, | |
| 132 'canEncrypt' => true, | |
| 133 'hasPrivate' => true, | |
| 134 'isRevoked' => true | |
| 135 )); | |
| 136 | |
| 137 $this->assertEquals('8C37DBD2A01B7976', $subKey->getId()); | |
| 138 $this->assertEquals(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 139 $subKey->getAlgorithm()); | |
| 140 | |
| 141 $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 142 $subKey->getFingerprint()); | |
| 143 | |
| 144 $this->assertEquals(2048, $subKey->getLength()); | |
| 145 $this->assertEquals(1221785858, $subKey->getCreationDate()); | |
| 146 $this->assertEquals(1421785858, $subKey->getExpirationDate()); | |
| 147 $this->assertFalse($subKey->canSign()); | |
| 148 $this->assertTrue($subKey->canEncrypt()); | |
| 149 $this->assertTrue($subKey->hasPrivate()); | |
| 150 $this->assertTrue($subKey->isRevoked()); | |
| 151 } | |
| 152 | |
| 153 // }}} | |
| 154 | |
| 155 // parse | |
| 156 // {{{ testParse() | |
| 157 | |
| 158 /** | |
| 159 * @group parse | |
| 160 */ | |
| 161 public function testParse() | |
| 162 { | |
| 163 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 164 'id' => '8C37DBD2A01B7976', | |
| 165 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 166 'length' => 2048, | |
| 167 'creation' => 1221528655, | |
| 168 'expiration' => 0, | |
| 169 'canSign' => false, | |
| 170 'canEncrypt' => true, | |
| 171 'isRevoked' => true | |
| 172 )); | |
| 173 | |
| 174 $string = 'sub:r:2048:16:8C37DBD2A01B7976:1221528655::::::e:'; | |
| 175 $subKey = Crypt_GPG_SubKey::parse($string); | |
| 176 | |
| 177 $this->assertEquals($expectedSubKey, $subKey); | |
| 178 | |
| 179 // test parsing 'usage' flags | |
| 180 $string = 'sub:r:2048:16:8C37DBD2A01B7976:1221528655::::::esca:'; | |
| 181 $subKey = Crypt_GPG_SubKey::parse($string); | |
| 182 $usage = Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_ENCRYPT | |
| 183 | Crypt_GPG_SubKey::USAGE_CERTIFY | Crypt_GPG_SubKey::USAGE_AUTHENTICATION; | |
| 184 | |
| 185 $this->assertEquals($usage, $subKey->usage()); | |
| 186 } | |
| 187 | |
| 188 // }}} | |
| 189 // {{{ testParseCreationDateIso() | |
| 190 | |
| 191 /** | |
| 192 * @group parse | |
| 193 */ | |
| 194 public function testParseCreationDateIso() | |
| 195 { | |
| 196 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 197 'id' => '8C37DBD2A01B7976', | |
| 198 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 199 'length' => 2048, | |
| 200 'creation' => 1221442255, | |
| 201 'expiration' => 0, | |
| 202 'canSign' => false, | |
| 203 'canEncrypt' => true | |
| 204 )); | |
| 205 | |
| 206 $string = 'sub:u:2048:16:8C37DBD2A01B7976:20080915T013055::::::e:'; | |
| 207 $subKey = Crypt_GPG_SubKey::parse($string); | |
| 208 | |
| 209 $this->assertEquals($expectedSubKey, $subKey); | |
| 210 } | |
| 211 | |
| 212 // }}} | |
| 213 | |
| 214 // accessors | |
| 215 // {{{ testGetId() | |
| 216 | |
| 217 /** | |
| 218 * @group accessors | |
| 219 */ | |
| 220 public function testGetId() | |
| 221 { | |
| 222 $subKey = new Crypt_GPG_SubKey(array( | |
| 223 'id' => '8C37DBD2A01B7976', | |
| 224 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 225 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 226 'length' => 2048, | |
| 227 'creation' => 1221785858, | |
| 228 'expiration' => 1421785858, | |
| 229 'canSign' => false, | |
| 230 'canEncrypt' => true, | |
| 231 'hasPrivate' => true | |
| 232 )); | |
| 233 | |
| 234 $this->assertEquals('8C37DBD2A01B7976', $subKey->getId()); | |
| 235 } | |
| 236 | |
| 237 // }}} | |
| 238 // {{{ testGetAlgorithm() | |
| 239 | |
| 240 /** | |
| 241 * @group accessors | |
| 242 */ | |
| 243 public function testGetAlgorithm() | |
| 244 { | |
| 245 $subKey = new Crypt_GPG_SubKey(array( | |
| 246 'id' => '8C37DBD2A01B7976', | |
| 247 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 248 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 249 'length' => 2048, | |
| 250 'creation' => 1221785858, | |
| 251 'expiration' => 1421785858, | |
| 252 'canSign' => false, | |
| 253 'canEncrypt' => true, | |
| 254 'hasPrivate' => true | |
| 255 )); | |
| 256 | |
| 257 $this->assertEquals(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 258 $subKey->getAlgorithm()); | |
| 259 } | |
| 260 | |
| 261 // }}} | |
| 262 // {{{ testGetFingerprint() | |
| 263 | |
| 264 /** | |
| 265 * @group accessors | |
| 266 */ | |
| 267 public function testGetFingerprint() | |
| 268 { | |
| 269 $subKey = new Crypt_GPG_SubKey(array( | |
| 270 'id' => '8C37DBD2A01B7976', | |
| 271 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 272 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 273 'length' => 2048, | |
| 274 'creation' => 1221785858, | |
| 275 'expiration' => 1421785858, | |
| 276 'canSign' => false, | |
| 277 'canEncrypt' => true, | |
| 278 'hasPrivate' => true | |
| 279 )); | |
| 280 | |
| 281 $this->assertEquals('8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 282 $subKey->getFingerprint()); | |
| 283 } | |
| 284 | |
| 285 // }}} | |
| 286 // {{{ testGetLength() | |
| 287 | |
| 288 /** | |
| 289 * @group accessors | |
| 290 */ | |
| 291 public function testGetLength() | |
| 292 { | |
| 293 $subKey = new Crypt_GPG_SubKey(array( | |
| 294 'id' => '8C37DBD2A01B7976', | |
| 295 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 296 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 297 'length' => 2048, | |
| 298 'creation' => 1221785858, | |
| 299 'expiration' => 1421785858, | |
| 300 'canSign' => false, | |
| 301 'canEncrypt' => true, | |
| 302 'hasPrivate' => true | |
| 303 )); | |
| 304 | |
| 305 $this->assertEquals(2048, $subKey->getLength()); | |
| 306 } | |
| 307 | |
| 308 // }}} | |
| 309 // {{{ testGetCreationDate() | |
| 310 | |
| 311 /** | |
| 312 * @group accessors | |
| 313 */ | |
| 314 public function testGetCreationDate() | |
| 315 { | |
| 316 $subKey = new Crypt_GPG_SubKey(array( | |
| 317 'id' => '8C37DBD2A01B7976', | |
| 318 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 319 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 320 'length' => 2048, | |
| 321 'creation' => 1221785858, | |
| 322 'expiration' => 1421785858, | |
| 323 'canSign' => false, | |
| 324 'canEncrypt' => true, | |
| 325 'hasPrivate' => true | |
| 326 )); | |
| 327 | |
| 328 $this->assertEquals(1221785858, $subKey->getCreationDate()); | |
| 329 } | |
| 330 | |
| 331 // }}} | |
| 332 // {{{ testGetExpirationDate() | |
| 333 | |
| 334 /** | |
| 335 * @group accessors | |
| 336 */ | |
| 337 public function testGetExpirationDate() | |
| 338 { | |
| 339 $subKey = new Crypt_GPG_SubKey(array( | |
| 340 'id' => '8C37DBD2A01B7976', | |
| 341 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 342 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 343 'length' => 2048, | |
| 344 'creation' => 1221785858, | |
| 345 'expiration' => 1421785858, | |
| 346 'canSign' => false, | |
| 347 'canEncrypt' => true, | |
| 348 'hasPrivate' => true | |
| 349 )); | |
| 350 | |
| 351 $this->assertEquals(1421785858, $subKey->getExpirationDate()); | |
| 352 } | |
| 353 | |
| 354 // }}} | |
| 355 // {{{ testCanSign() | |
| 356 | |
| 357 /** | |
| 358 * @group accessors | |
| 359 */ | |
| 360 public function testCanSign() | |
| 361 { | |
| 362 $subKey = new Crypt_GPG_SubKey(array( | |
| 363 'id' => '8C37DBD2A01B7976', | |
| 364 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 365 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 366 'length' => 1024, | |
| 367 'creation' => 1221785858, | |
| 368 'expiration' => 1421785858, | |
| 369 'canSign' => true, | |
| 370 'canEncrypt' => false, | |
| 371 'hasPrivate' => true | |
| 372 )); | |
| 373 | |
| 374 $this->assertTrue($subKey->canSign()); | |
| 375 | |
| 376 $subKey = new Crypt_GPG_SubKey(array( | |
| 377 'id' => '8C37DBD2A01B7976', | |
| 378 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 379 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 380 'length' => 2048, | |
| 381 'creation' => 1221785858, | |
| 382 'expiration' => 1421785858, | |
| 383 'canSign' => false, | |
| 384 'canEncrypt' => true, | |
| 385 'hasPrivate' => true | |
| 386 )); | |
| 387 | |
| 388 $this->assertFalse($subKey->canSign()); | |
| 389 } | |
| 390 | |
| 391 // }}} | |
| 392 // {{{ testCanEncrypt() | |
| 393 | |
| 394 /** | |
| 395 * @group accessors | |
| 396 */ | |
| 397 public function testCanEncrypt() | |
| 398 { | |
| 399 $subKey = new Crypt_GPG_SubKey(array( | |
| 400 'id' => '8C37DBD2A01B7976', | |
| 401 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 402 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 403 'length' => 2048, | |
| 404 'creation' => 1221785858, | |
| 405 'expiration' => 1421785858, | |
| 406 'canSign' => false, | |
| 407 'canEncrypt' => true, | |
| 408 'hasPrivate' => true | |
| 409 )); | |
| 410 | |
| 411 $this->assertTrue($subKey->canEncrypt()); | |
| 412 | |
| 413 $subKey = new Crypt_GPG_SubKey(array( | |
| 414 'id' => '8C37DBD2A01B7976', | |
| 415 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 416 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 417 'length' => 1024, | |
| 418 'creation' => 1221785858, | |
| 419 'expiration' => 1421785858, | |
| 420 'canSign' => true, | |
| 421 'canEncrypt' => false, | |
| 422 'hasPrivate' => true | |
| 423 )); | |
| 424 | |
| 425 $this->assertFalse($subKey->canEncrypt()); | |
| 426 } | |
| 427 | |
| 428 // }}} | |
| 429 // {{{ testUsage() | |
| 430 | |
| 431 /** | |
| 432 * @group accessors | |
| 433 */ | |
| 434 public function testUsage() | |
| 435 { | |
| 436 $usage = Crypt_GPG_SubKey::USAGE_SIGN | Crypt_GPG_SubKey::USAGE_ENCRYPT | |
| 437 | Crypt_GPG_SubKey::USAGE_CERTIFY | Crypt_GPG_SubKey::USAGE_AUTHENTICATION; | |
| 438 $subKey = new Crypt_GPG_SubKey(array( | |
| 439 'id' => '8C37DBD2A01B7976', | |
| 440 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 441 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 442 'length' => 2048, | |
| 443 'creation' => 1221785858, | |
| 444 'expiration' => 1421785858, | |
| 445 'usage' => $usage, | |
| 446 'hasPrivate' => true | |
| 447 )); | |
| 448 | |
| 449 $this->assertSame($usage, $subKey->usage()); | |
| 450 | |
| 451 $subKey = new Crypt_GPG_SubKey(array( | |
| 452 'id' => '8C37DBD2A01B7976', | |
| 453 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 454 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 455 'length' => 1024, | |
| 456 'creation' => 1221785858, | |
| 457 'expiration' => 1421785858, | |
| 458 'canSign' => true, | |
| 459 'canEncrypt' => false, | |
| 460 'hasPrivate' => true | |
| 461 )); | |
| 462 | |
| 463 $this->assertSame(Crypt_GPG_SubKey::USAGE_SIGN, $subKey->usage()); | |
| 464 } | |
| 465 | |
| 466 // }}} | |
| 467 // {{{ testHasPrivate() | |
| 468 | |
| 469 /** | |
| 470 * @group accessors | |
| 471 */ | |
| 472 public function testHasPrivate() | |
| 473 { | |
| 474 $subKey = new Crypt_GPG_SubKey(array( | |
| 475 'id' => '8C37DBD2A01B7976', | |
| 476 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 477 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 478 'length' => 1024, | |
| 479 'creation' => 1221785858, | |
| 480 'expiration' => 1421785858, | |
| 481 'canSign' => true, | |
| 482 'canEncrypt' => false, | |
| 483 'hasPrivate' => true | |
| 484 )); | |
| 485 | |
| 486 $this->assertTrue($subKey->hasPrivate()); | |
| 487 | |
| 488 $subKey = new Crypt_GPG_SubKey(array( | |
| 489 'id' => '8C37DBD2A01B7976', | |
| 490 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 491 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 492 'length' => 1024, | |
| 493 'creation' => 1221785858, | |
| 494 'expiration' => 1421785858, | |
| 495 'canSign' => true, | |
| 496 'canEncrypt' => false, | |
| 497 'hasPrivate' => false | |
| 498 )); | |
| 499 | |
| 500 $this->assertFalse($subKey->hasPrivate()); | |
| 501 } | |
| 502 | |
| 503 // }}} | |
| 504 // {{{ testIsRevoked() | |
| 505 | |
| 506 /** | |
| 507 * @group accessors | |
| 508 */ | |
| 509 public function testIsRevoked() | |
| 510 { | |
| 511 $subKey = new Crypt_GPG_SubKey(array( | |
| 512 'id' => '8C37DBD2A01B7976', | |
| 513 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 514 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 515 'length' => 1024, | |
| 516 'creation' => 1221785858, | |
| 517 'expiration' => 1421785858, | |
| 518 'canSign' => true, | |
| 519 'canEncrypt' => false, | |
| 520 'hasPrivate' => true, | |
| 521 'isRevoked' => true | |
| 522 )); | |
| 523 | |
| 524 $this->assertTrue($subKey->isRevoked()); | |
| 525 | |
| 526 $subKey = new Crypt_GPG_SubKey(array( | |
| 527 'id' => '8C37DBD2A01B7976', | |
| 528 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 529 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 530 'length' => 1024, | |
| 531 'creation' => 1221785858, | |
| 532 'expiration' => 1421785858, | |
| 533 'canSign' => true, | |
| 534 'canEncrypt' => false, | |
| 535 'hasPrivate' => false, | |
| 536 'isRevoked' => false | |
| 537 )); | |
| 538 | |
| 539 $this->assertFalse($subKey->isRevoked()); | |
| 540 } | |
| 541 | |
| 542 // }}} | |
| 543 | |
| 544 // mutators | |
| 545 // {{{ testSetId() | |
| 546 | |
| 547 /** | |
| 548 * @group mutators | |
| 549 */ | |
| 550 public function testSetId() | |
| 551 { | |
| 552 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 553 'id' => '8C37DBD2A01B7976', | |
| 554 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 555 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 556 'length' => 2048, | |
| 557 'creation' => 1221785858, | |
| 558 'expiration' => 1421785858, | |
| 559 'canSign' => false, | |
| 560 'canEncrypt' => true, | |
| 561 'hasPrivate' => true | |
| 562 )); | |
| 563 | |
| 564 $subKey = new Crypt_GPG_SubKey(array( | |
| 565 'id' => 'something different', | |
| 566 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 567 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 568 'length' => 2048, | |
| 569 'creation' => 1221785858, | |
| 570 'expiration' => 1421785858, | |
| 571 'canSign' => false, | |
| 572 'canEncrypt' => true, | |
| 573 'hasPrivate' => true | |
| 574 )); | |
| 575 | |
| 576 $subKey->setId('8C37DBD2A01B7976'); | |
| 577 | |
| 578 $this->assertEquals($expectedSubKey, $subKey); | |
| 579 } | |
| 580 | |
| 581 // }}} | |
| 582 // {{{ testSetAlgorithm() | |
| 583 | |
| 584 /** | |
| 585 * @group mutators | |
| 586 */ | |
| 587 public function testSetAlgorithm() | |
| 588 { | |
| 589 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 590 'id' => '8C37DBD2A01B7976', | |
| 591 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 592 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 593 'length' => 2048, | |
| 594 'creation' => 1221785858, | |
| 595 'expiration' => 1421785858, | |
| 596 'canSign' => false, | |
| 597 'canEncrypt' => true, | |
| 598 'hasPrivate' => true | |
| 599 )); | |
| 600 | |
| 601 $subKey = new Crypt_GPG_SubKey(array( | |
| 602 'id' => '8C37DBD2A01B7976', | |
| 603 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 604 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 605 'length' => 2048, | |
| 606 'creation' => 1221785858, | |
| 607 'expiration' => 1421785858, | |
| 608 'canSign' => false, | |
| 609 'canEncrypt' => true, | |
| 610 'hasPrivate' => true | |
| 611 )); | |
| 612 | |
| 613 $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC); | |
| 614 | |
| 615 $this->assertEquals($expectedSubKey, $subKey); | |
| 616 } | |
| 617 | |
| 618 // }}} | |
| 619 // {{{ testSetFingerprint() | |
| 620 | |
| 621 /** | |
| 622 * @group mutators | |
| 623 */ | |
| 624 public function testSetFingerprint() | |
| 625 { | |
| 626 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 627 'id' => '8C37DBD2A01B7976', | |
| 628 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 629 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 630 'length' => 2048, | |
| 631 'creation' => 1221785858, | |
| 632 'expiration' => 1421785858, | |
| 633 'canSign' => false, | |
| 634 'canEncrypt' => true, | |
| 635 'hasPrivate' => true | |
| 636 )); | |
| 637 | |
| 638 $subKey = new Crypt_GPG_SubKey(array( | |
| 639 'id' => '8C37DBD2A01B7976', | |
| 640 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 641 'fingerprint' => 'something different', | |
| 642 'length' => 2048, | |
| 643 'creation' => 1221785858, | |
| 644 'expiration' => 1421785858, | |
| 645 'canSign' => false, | |
| 646 'canEncrypt' => true, | |
| 647 'hasPrivate' => true | |
| 648 )); | |
| 649 | |
| 650 $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363'); | |
| 651 | |
| 652 $this->assertEquals($expectedSubKey, $subKey); | |
| 653 } | |
| 654 | |
| 655 // }}} | |
| 656 // {{{ testSetLength() | |
| 657 | |
| 658 /** | |
| 659 * @group mutators | |
| 660 */ | |
| 661 public function testSetLength() | |
| 662 { | |
| 663 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 664 'id' => '8C37DBD2A01B7976', | |
| 665 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 666 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 667 'length' => 2048, | |
| 668 'creation' => 1221785858, | |
| 669 'expiration' => 1421785858, | |
| 670 'canSign' => false, | |
| 671 'canEncrypt' => true, | |
| 672 'hasPrivate' => true | |
| 673 )); | |
| 674 | |
| 675 $subKey = new Crypt_GPG_SubKey(array( | |
| 676 'id' => '8C37DBD2A01B7976', | |
| 677 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 678 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 679 'length' => 1024, | |
| 680 'creation' => 1221785858, | |
| 681 'expiration' => 1421785858, | |
| 682 'canSign' => false, | |
| 683 'canEncrypt' => true, | |
| 684 'hasPrivate' => true | |
| 685 )); | |
| 686 | |
| 687 $subKey->setLength(2048); | |
| 688 | |
| 689 $this->assertEquals($expectedSubKey, $subKey); | |
| 690 } | |
| 691 | |
| 692 // }}} | |
| 693 // {{{ testSetCreationDate() | |
| 694 | |
| 695 /** | |
| 696 * @group mutators | |
| 697 */ | |
| 698 public function testSetCreationDate() | |
| 699 { | |
| 700 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 701 'id' => '8C37DBD2A01B7976', | |
| 702 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 703 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 704 'length' => 2048, | |
| 705 'creation' => 1221785858, | |
| 706 'expiration' => 1421785858, | |
| 707 'canSign' => false, | |
| 708 'canEncrypt' => true, | |
| 709 'hasPrivate' => true | |
| 710 )); | |
| 711 | |
| 712 $subKey = new Crypt_GPG_SubKey(array( | |
| 713 'id' => '8C37DBD2A01B7976', | |
| 714 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 715 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 716 'length' => 2048, | |
| 717 'creation' => 1111111111, | |
| 718 'expiration' => 1421785858, | |
| 719 'canSign' => false, | |
| 720 'canEncrypt' => true, | |
| 721 'hasPrivate' => true | |
| 722 )); | |
| 723 | |
| 724 $subKey->setCreationDate(1221785858); | |
| 725 | |
| 726 $this->assertEquals($expectedSubKey, $subKey); | |
| 727 } | |
| 728 | |
| 729 // }}} | |
| 730 // {{{ testSetExpirationDate() | |
| 731 | |
| 732 /** | |
| 733 * @group mutators | |
| 734 */ | |
| 735 public function testSetExpirationDate() | |
| 736 { | |
| 737 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 738 'id' => '8C37DBD2A01B7976', | |
| 739 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 740 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 741 'length' => 2048, | |
| 742 'creation' => 1221785858, | |
| 743 'expiration' => 1421785858, | |
| 744 'canSign' => false, | |
| 745 'canEncrypt' => true, | |
| 746 'hasPrivate' => true | |
| 747 )); | |
| 748 | |
| 749 $subKey = new Crypt_GPG_SubKey(array( | |
| 750 'id' => '8C37DBD2A01B7976', | |
| 751 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 752 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 753 'length' => 2048, | |
| 754 'creation' => 1221785858, | |
| 755 'expiration' => 1111111111, | |
| 756 'canSign' => false, | |
| 757 'canEncrypt' => true, | |
| 758 'hasPrivate' => true | |
| 759 )); | |
| 760 | |
| 761 $subKey->setExpirationDate(1421785858); | |
| 762 | |
| 763 $this->assertEquals($expectedSubKey, $subKey); | |
| 764 } | |
| 765 | |
| 766 // }}} | |
| 767 // {{{ testSetCanSign() | |
| 768 | |
| 769 /** | |
| 770 * @group mutators | |
| 771 */ | |
| 772 public function testSetCanSign() | |
| 773 { | |
| 774 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 775 'id' => '8C37DBD2A01B7976', | |
| 776 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 777 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 778 'length' => 1024, | |
| 779 'creation' => 1221785858, | |
| 780 'expiration' => 1421785858, | |
| 781 'canSign' => true, | |
| 782 'canEncrypt' => false, | |
| 783 'hasPrivate' => true | |
| 784 )); | |
| 785 | |
| 786 $subKey = new Crypt_GPG_SubKey(array( | |
| 787 'id' => '8C37DBD2A01B7976', | |
| 788 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_DSA, | |
| 789 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 790 'length' => 1024, | |
| 791 'creation' => 1221785858, | |
| 792 'expiration' => 1421785858, | |
| 793 'canSign' => false, | |
| 794 'canEncrypt' => false, | |
| 795 'hasPrivate' => true | |
| 796 )); | |
| 797 | |
| 798 $subKey->setCanSign(true); | |
| 799 | |
| 800 $this->assertEquals($expectedSubKey, $subKey); | |
| 801 } | |
| 802 | |
| 803 // }}} | |
| 804 // {{{ testSetCanEncrypt() | |
| 805 | |
| 806 /** | |
| 807 * @group mutators | |
| 808 */ | |
| 809 public function testSetCanEncrypt() | |
| 810 { | |
| 811 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 812 'id' => '8C37DBD2A01B7976', | |
| 813 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 814 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 815 'length' => 2048, | |
| 816 'creation' => 1221785858, | |
| 817 'expiration' => 1421785858, | |
| 818 'canSign' => false, | |
| 819 'canEncrypt' => true, | |
| 820 'hasPrivate' => true | |
| 821 )); | |
| 822 | |
| 823 $subKey = new Crypt_GPG_SubKey(array( | |
| 824 'id' => '8C37DBD2A01B7976', | |
| 825 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 826 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 827 'length' => 2048, | |
| 828 'creation' => 1221785858, | |
| 829 'expiration' => 1421785858, | |
| 830 'canSign' => false, | |
| 831 'canEncrypt' => false, | |
| 832 'hasPrivate' => true | |
| 833 )); | |
| 834 | |
| 835 $subKey->setCanEncrypt(true); | |
| 836 | |
| 837 $this->assertEquals($expectedSubKey, $subKey); | |
| 838 } | |
| 839 | |
| 840 // }}} | |
| 841 // {{{ testSetHasPrivate() | |
| 842 | |
| 843 /** | |
| 844 * @group mutators | |
| 845 */ | |
| 846 public function testSetHasPrivate() | |
| 847 { | |
| 848 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 849 'id' => '8C37DBD2A01B7976', | |
| 850 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 851 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 852 'length' => 2048, | |
| 853 'creation' => 1221785858, | |
| 854 'expiration' => 1421785858, | |
| 855 'canSign' => false, | |
| 856 'canEncrypt' => false, | |
| 857 'hasPrivate' => true | |
| 858 )); | |
| 859 | |
| 860 $subKey = new Crypt_GPG_SubKey(array( | |
| 861 'id' => '8C37DBD2A01B7976', | |
| 862 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 863 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 864 'length' => 2048, | |
| 865 'creation' => 1221785858, | |
| 866 'expiration' => 1421785858, | |
| 867 'canSign' => false, | |
| 868 'canEncrypt' => false, | |
| 869 'hasPrivate' => false | |
| 870 )); | |
| 871 | |
| 872 $subKey->setHasPrivate(true); | |
| 873 | |
| 874 $this->assertEquals($expectedSubKey, $subKey); | |
| 875 } | |
| 876 | |
| 877 // }}} | |
| 878 // {{{ testSetRevoked() | |
| 879 | |
| 880 /** | |
| 881 * @group mutators | |
| 882 */ | |
| 883 public function testSetRevoked() | |
| 884 { | |
| 885 $expectedSubKey = new Crypt_GPG_SubKey(array( | |
| 886 'id' => '8C37DBD2A01B7976', | |
| 887 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 888 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 889 'length' => 2048, | |
| 890 'creation' => 1221785858, | |
| 891 'expiration' => 1421785858, | |
| 892 'canSign' => false, | |
| 893 'canEncrypt' => false, | |
| 894 'hasPrivate' => false, | |
| 895 'isRevoked' => true | |
| 896 )); | |
| 897 | |
| 898 $subKey = new Crypt_GPG_SubKey(array( | |
| 899 'id' => '8C37DBD2A01B7976', | |
| 900 'algorithm' => Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC, | |
| 901 'fingerprint' => '8D2299D9C5C211128B32BBB0C097D9EC94C06363', | |
| 902 'length' => 2048, | |
| 903 'creation' => 1221785858, | |
| 904 'expiration' => 1421785858, | |
| 905 'canSign' => false, | |
| 906 'canEncrypt' => false, | |
| 907 'hasPrivate' => false, | |
| 908 'isRevoked' => false | |
| 909 )); | |
| 910 | |
| 911 $subKey->setRevoked(true); | |
| 912 | |
| 913 $this->assertEquals($expectedSubKey, $subKey); | |
| 914 } | |
| 915 | |
| 916 // }}} | |
| 917 | |
| 918 // fluent interface | |
| 919 // {{{ testFluentInterface | |
| 920 | |
| 921 /** | |
| 922 * @group fluent | |
| 923 */ | |
| 924 public function testFluentInterface() | |
| 925 { | |
| 926 $subKey = new Crypt_GPG_SubKey(); | |
| 927 $returnedSubKey = $subKey->setId('8C37DBD2A01B7976'); | |
| 928 $this->assertEquals( | |
| 929 $subKey, | |
| 930 $returnedSubKey, | |
| 931 'Failed asserting fluent interface works for setId() method.' | |
| 932 ); | |
| 933 | |
| 934 $subKey = new Crypt_GPG_SubKey(); | |
| 935 $returnedSubKey = $subKey->setAlgorithm( | |
| 936 Crypt_GPG_SubKey::ALGORITHM_DSA | |
| 937 ); | |
| 938 $this->assertEquals( | |
| 939 $subKey, | |
| 940 $returnedSubKey, | |
| 941 'Failed asserting fluent interface works for setAlgorithm() method.' | |
| 942 ); | |
| 943 | |
| 944 $subKey = new Crypt_GPG_SubKey(); | |
| 945 $returnedSubKey = $subKey->setFingerprint( | |
| 946 '8D2299D9C5C211128B32BBB0C097D9EC94C06363' | |
| 947 ); | |
| 948 $this->assertEquals( | |
| 949 $subKey, | |
| 950 $returnedSubKey, | |
| 951 'Failed asserting fluent interface works for setFingerprint() ' . | |
| 952 'method.' | |
| 953 ); | |
| 954 | |
| 955 $subKey = new Crypt_GPG_SubKey(); | |
| 956 $returnedSubKey = $subKey->setLength(2048); | |
| 957 $this->assertEquals( | |
| 958 $subKey, | |
| 959 $returnedSubKey, | |
| 960 'Failed asserting fluent interface works for setLength() method.' | |
| 961 ); | |
| 962 | |
| 963 $subKey = new Crypt_GPG_SubKey(); | |
| 964 $returnedSubKey = $subKey->setCreationDate(1234567890); | |
| 965 $this->assertEquals( | |
| 966 $subKey, | |
| 967 $returnedSubKey, | |
| 968 'Failed asserting fluent interface works for setCreationDate() ' . | |
| 969 'method.' | |
| 970 ); | |
| 971 | |
| 972 $subKey = new Crypt_GPG_SubKey(); | |
| 973 $returnedSubKey = $subKey->setExpirationDate(1234567890); | |
| 974 $this->assertEquals( | |
| 975 $subKey, | |
| 976 $returnedSubKey, | |
| 977 'Failed asserting fluent interface works for setExpirationDate() ' . | |
| 978 'method.' | |
| 979 ); | |
| 980 | |
| 981 $subKey = new Crypt_GPG_SubKey(); | |
| 982 $returnedSubKey = $subKey->setCanSign(true); | |
| 983 $this->assertEquals( | |
| 984 $subKey, | |
| 985 $returnedSubKey, | |
| 986 'Failed asserting fluent interface works for setCanSign() method.' | |
| 987 ); | |
| 988 | |
| 989 $subKey = new Crypt_GPG_SubKey(); | |
| 990 $returnedSubKey = $subKey->setCanEncrypt(true); | |
| 991 $this->assertEquals( | |
| 992 $subKey, | |
| 993 $returnedSubKey, | |
| 994 'Failed asserting fluent interface works for setCanEncrypt() ' . | |
| 995 'method.' | |
| 996 ); | |
| 997 | |
| 998 $subKey = new Crypt_GPG_SubKey(); | |
| 999 $returnedSubKey = $subKey->setHasPrivate(true); | |
| 1000 $this->assertEquals( | |
| 1001 $subKey, | |
| 1002 $returnedSubKey, | |
| 1003 'Failed asserting fluent interface works for setHasPrivate() ' . | |
| 1004 'method.' | |
| 1005 ); | |
| 1006 | |
| 1007 $subKey = new Crypt_GPG_SubKey(); | |
| 1008 $returnedSubKey = $subKey->setRevoked(true); | |
| 1009 $this->assertEquals( | |
| 1010 $subKey, | |
| 1011 $returnedSubKey, | |
| 1012 'Failed asserting fluent interface works for setRevoked() method.' | |
| 1013 ); | |
| 1014 } | |
| 1015 | |
| 1016 // }}} | |
| 1017 } | |
| 1018 | |
| 1019 ?> |
