Beispiel #1
0
 public static function parseUserIdLine($string)
 {
     $userId = new UserId();
     $email = '';
     $comment = '';
     $uid = '';
     // get email address from end of string if it exists
     $matches = array();
     if (preg_match('/^(.+?) <([^>]+)>$/', $string, $matches) === 1) {
         $string = $matches[1];
         $email = $matches[2];
     }
     // get comment from end of string if it exists
     $matches = array();
     if (preg_match('/^(.+?) \\(([^\\)]+)\\)$/', $string, $matches) === 1) {
         $string = $matches[1];
         $comment = $matches[2];
     }
     $name = $string;
     $userId->setName($name);
     $userId->setComment($comment);
     $userId->setEmail($email);
     if (!empty($name)) {
         $uid .= $name;
     }
     if (!empty($comment)) {
         if (!empty($uid)) {
             $uid .= " ";
         }
         $uid .= "({$comment})";
     }
     if (!empty($email)) {
         if (!empty($uid)) {
             $uid .= " ";
         }
         $uid .= "<{$email}>";
     }
     $userId->setUid($uid);
     return $userId;
 }
Beispiel #2
0
 public function getKeys($keyId = null)
 {
     $keys = array();
     $data = $this->getResource()->keyinfo($keyId);
     foreach ($data as $kd) {
         $key = new Key();
         foreach ($kd['subkeys'] as $skd) {
             $subKey = new SubKey();
             $subKey->setCanEncrypt($skd['can_encrypt']);
             $subKey->setCanSign($skd['can_sign']);
             $subKey->setCreationDate($skd['timestamp']);
             $subKey->setExpirationDate($skd['expires']);
             $subKey->setFingerprint($skd['fingerprint']);
             $subKey->setHasPrivate(false);
             $subKey->setId($skd['keyid']);
             $subKey->setRevoked($skd['revoked']);
             $subKey->setDisabled($skd['disabled']);
             //$subKey->setLength($skd['can_encrypt']);
             //$subKey->setAlgorithm();
             $key->addSubKey($subKey);
         }
         foreach ($kd['uids'] as $uid) {
             $userId = new UserId();
             $userId->setName($uid['name']);
             $userId->setComment($uid['comment']);
             $userId->setEmail($uid['email']);
             $userId->setUid($uid['uid']);
             $userId->setIsRevoked($uid['revoked']);
             $userId->setIsValid($uid['invalid'] ? false : true);
             $key->addUserId($userId);
         }
         $keys[] = $key;
     }
     return $keys;
 }