/** * @param array|string $formats * @param string $blob * @return Message * @throws InvalidMessageException */ public function decode($formats, $blob) { $formats = (array) $formats; $prefixLen = 0; foreach ($formats as $format) { $prefixLen = max($prefixLen, strlen($format)); } list($prefix) = explode(Constants::PROTOCOL_DELIM, substr($blob, 0, $prefixLen + 1)); if (!in_array($prefix, $formats)) { if (in_array(GarbledMessage::NAME, $formats)) { return GarbledMessage::decode($blob); } else { throw new InvalidMessageException("Unexpected message type."); } } switch ($prefix) { case StdMessage::NAME: return StdMessage::decode($this->cxnStore, $blob); case InsecureMessage::NAME: return InsecureMessage::decode($blob); case RegistrationMessage::NAME: return RegistrationMessage::decode($this->appStore, $blob); case AppMetasMessage::NAME: return AppMetasMessage::decode($this->certValidator, $blob); default: throw new InvalidMessageException("Unrecognized message type."); } }
/** * The application does not want to verify the authenticity of the app list, * so it's valid - even if signed by someone else. */ public function testUnsignedValid() { list($caKeyPair, $caCert) = $this->createCA(); $distPointKeyPair = KeyPair::create(); $distPointCert = CA::signCSR($caKeyPair, $caCert, CA::createDirSvcCSR($distPointKeyPair, 'O=Someone, CN=else')); $msg = new AppMetasMessage($distPointCert, $distPointKeyPair, array('app-2' => array('appId' => 'app-2'))); $appMetas = AppMetasMessage::decode(NULL, $msg->encode())->getData(); $this->assertEquals('app-2', $appMetas['app-2']['appId']); }