示例#1
0
 /**
  * Fetch a public key and check the capability of the threemaId
  *
  * @param string $threemaId
  * @param \Closure $capabilityCheck
  * @return string Public key as binary
  * @throws Exception
  */
 private final function fetchPublicKeyAndCheckCapability($threemaId, \Closure $capabilityCheck = null)
 {
     //fetch the public key
     $receiverPublicKey = $this->connection->fetchPublicKey($threemaId);
     if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) {
         throw new Exception('Invalid threema id');
     }
     if (null !== $capabilityCheck) {
         //check capability
         $capability = $this->connection->keyCapability($threemaId);
         if (null === $capability || false === $capabilityCheck->__invoke($capability)) {
             throw new Exception('threema id does not have the capability');
         }
     }
     return $this->cryptTool->hex2bin($receiverPublicKey->getPublicKey());
 }
 protected function doRun()
 {
     $threemaId = $this->getArgumentThreemaId(self::argThreemaId);
     $from = $this->getArgumentThreemaId(self::argFrom);
     $secret = $this->getArgument(self::argSecret);
     Common::required($threemaId, $from, $secret);
     if (strlen($threemaId) != 8) {
         throw new Exception('invalid threema id');
     }
     //define connection settings
     $settings = new ConnectionSettings($from, $secret);
     //create a connection
     $connector = new Connection($settings, $this->publicKeyStore);
     $result = $connector->keyCapability($threemaId);
     Common::required($result);
     if ($result->isSuccess()) {
         Common::l(implode("\n", $result->getCapabilities()));
     } else {
         Common::e($result->getErrorMessage());
     }
 }