Exemplo n.º 1
0
 /**
  * Parses a sub-key object from a sub-key string
  *
  * See <b>doc/DETAILS</b> in the
  * {@link http://www.gnupg.org/download/ GPG distribution} for information
  * on how the sub-key string is parsed.
  *
  * @param string $string the string containing the sub-key.
  *
  * @return Crypt_GPG_SubKey the sub-key object parsed from the string.
  */
 public static function parse($string)
 {
     $tokens = explode(':', $string);
     $subKey = new Crypt_GPG_SubKey();
     $subKey->setId($tokens[4]);
     $subKey->setLength($tokens[2]);
     $subKey->setAlgorithm($tokens[3]);
     $subKey->setCreationDate(self::_parseDate($tokens[5]));
     $subKey->setExpirationDate(self::_parseDate($tokens[6]));
     if ($tokens[1] == 'r') {
         $subKey->setRevoked(true);
     }
     $usage = 0;
     $usage_map = array('a' => self::USAGE_AUTHENTICATION, 'c' => self::USAGE_CERTIFY, 'e' => self::USAGE_ENCRYPT, 's' => self::USAGE_SIGN);
     foreach ($usage_map as $key => $flag) {
         if (strpos($tokens[11], $key) !== false) {
             $usage |= $flag;
         }
     }
     $subKey->setUsage($usage);
     return $subKey;
 }
Exemplo n.º 2
0
 /**
  * Parses a sub-key object from a sub-key string
  *
  * See <b>doc/DETAILS</b> in the
  * {@link http://www.gnupg.org/download/ GPG distribution} for information
  * on how the sub-key string is parsed.
  *
  * @param string $string the string containing the sub-key.
  *
  * @return Crypt_GPG_SubKey the sub-key object parsed from the string.
  */
 public static function parse($string)
 {
     $tokens = explode(':', $string);
     $subKey = new Crypt_GPG_SubKey();
     $subKey->setId($tokens[4]);
     $subKey->setLength($tokens[2]);
     $subKey->setAlgorithm($tokens[3]);
     $subKey->setCreationDate(self::_parseDate($tokens[5]));
     $subKey->setExpirationDate(self::_parseDate($tokens[6]));
     if ($tokens[1] == 'r') {
         $subKey->setRevoked(true);
     }
     if (strpos($tokens[11], 's') !== false) {
         $subKey->setCanSign(true);
     }
     if (strpos($tokens[11], 'e') !== false) {
         $subKey->setCanEncrypt(true);
     }
     return $subKey;
 }
Exemplo n.º 3
0
 /**
  * @group fluent
  */
 public function testFluentInterface()
 {
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setId('8C37DBD2A01B7976');
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setId() method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setAlgorithm(Crypt_GPG_SubKey::ALGORITHM_DSA);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setAlgorithm() method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setFingerprint('8D2299D9C5C211128B32BBB0C097D9EC94C06363');
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setFingerprint() ' . 'method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setLength(2048);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setLength() method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setCreationDate(1234567890);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setCreationDate() ' . 'method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setExpirationDate(1234567890);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setExpirationDate() ' . 'method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setCanSign(true);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setCanSign() method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setCanEncrypt(true);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setCanEncrypt() ' . 'method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setHasPrivate(true);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setHasPrivate() ' . 'method.');
     $subKey = new Crypt_GPG_SubKey();
     $returnedSubKey = $subKey->setRevoked(true);
     $this->assertEquals($subKey, $returnedSubKey, 'Failed asserting fluent interface works for setRevoked() method.');
 }