示例#1
0
 /**
  * Signs arbitrary byte array using per app private key.
  *
  * @param string $bytes_to_sign The bytes to generate the signature for.
  *
  * @throws \InvalidArgumentException If $bytes_to_sign is not a string.
  * @throws AppIdentityException If there is an error using the AppIdentity
  * service.
  *
  * @return array An array containing the elements
  * 'key_name' - the name of the key used to sign the bytes
  * 'signature' - the signature of the bytes.
  *
  */
 public static function signForApp($bytes_to_sign)
 {
     $req = new SignForAppRequest();
     $resp = new SignForAppResponse();
     if (!is_string($bytes_to_sign)) {
         throw new \InvalidArgumentException('$bytes_to_sign must be a string.');
     }
     $req->setBytesToSign($bytes_to_sign);
     try {
         ApiProxy::makeSyncCall(self::PACKAGE_NAME, 'SignForApp', $req, $resp);
     } catch (ApplicationError $e) {
         throw self::applicationErrorToException($e);
     }
     return ['key_name' => $resp->getKeyName(), 'signature' => $resp->getSignatureBytes()];
 }
 public function testRpcDevTicket()
 {
     $expected_request = new SignForAppRequest();
     $expected_response = new SignForAppResponse();
     $expected_request->setBytesToSign("SomeBytes");
     $expected_response->setKeyName("TheKeyName");
     $ticket = 'TheDevTicket';
     putenv(VmApiProxy::TICKET_HEADER);
     putenv(VmApiProxy::DEV_TICKET_HEADER . "={$ticket}");
     $options = ['ticket' => $ticket];
     $this->expectRpc($expected_request, $expected_response, $options);
     $response = new SignForAppResponse();
     ApiProxy::makeSyncCall(self::PACKAGE_NAME, self::CALL_NAME, $expected_request, $response);
     $this->assertEquals($response->getKeyName(), "TheKeyName");
     putenv(VmApiProxy::DEV_TICKET_HEADER);
 }