Example #1
0
 public function writeTo($outputFunction)
 {
     if (Nife_Util::isEchoFunction($outputFunction)) {
         call_user_func($this->outputtable);
     } else {
         call_user_func($outputFunction, $this->__toString());
     }
 }
 public function testVerifyValidSignature()
 {
     $keyPair = TOGoS_RSAUtil_KeyPair::generate(array('size' => 1024));
     // For faster unit testing
     $DS = new TOGoS_RSAUtil_DataStore();
     $pubKeyUri = $DS->store($keyPair->getPublicKeyDer());
     // I guess we're also testing generateKeyPair, then.
     $this->assertEquals($pubKeyUri, $keyPair->getPublicKeyUri());
     $data = "Hello, world!";
     $sig = TOGoS_RSAUtil::sign($data, $keyPair);
     $this->assertTrue(TOGoS_RSAUtil::verif($sig, $DS), "Signature should have verified!");
     // Change the data and make sure the signature's no longer valid!
     $badSig = new TOGoS_RSAUtil_Signature($sig->getPublicKeyUri(), Nife_Util::blob($data . '; drop all tables'), $sig->getAlgorithmName(), $sig->getSignatureBytes());
     $this->assertFalse(TOGoS_RSAUtil::verif($badSig, $DS), "Signature should have verified!");
 }
Example #3
0
 public function testEchoOutputFunction()
 {
     $collector = new Nife_Collector();
     $echoer = Nife_Util::getEchoFunction();
     $blob = new Nife_FooBarBazBlob();
     $this->assertTrue(Nife_Util::isEchoFunction($echoer));
     $this->assertFalse(Nife_Util::isEchoFunction($collector));
     $blob->writeTo($collector);
     $this->assertEquals("FooBarBaz", (string) $collector);
     ob_start();
     $blob->writeTo($echoer);
     $echoed = ob_get_contents();
     ob_end_clean();
     $this->assertEquals("FooBarBaz", $echoed);
 }
Example #4
0
 /**
  * Returns a Signature object
  */
 public static function sign($data, TOGoS_RSAUtil_KeyPair $keyPair, $sslAlgo = OPENSSL_ALGO_SHA1)
 {
     openssl_sign((string) $data, $sigBytes, $keyPair->getPrivateKeyPem(), $sslAlgo);
     return new TOGoS_RSAUtil_Signature($keyPair->getPublicKeyUri(), Nife_Util::blob($data), TOGoS_RSAUtil_Util::rsaAlgoNameFromId($sslAlgo), $sigBytes);
 }
Example #5
0
 protected function setContent(Nife_Blob $content = null)
 {
     $content = Nife_Util::blob($content);
     $this->contentFuture = new Nife_Futures_Constant($content);
 }
Example #6
0
 public function store($data)
 {
     $id = "urn:sha1:" . TOGoS_Base32::encode(hash('sha1', (string) $data, true));
     $this->store[$id] = Nife_Util::blob($data);
     return $id;
 }
Example #7
0
 public static function emit($thing, $indent = "", $indentDelta = "\t")
 {
     $emitter = new EarthIT_PAXML_PAXMLEmitter();
     $emitter->emit($thing, $indent, $indentDelta, Nife_Util::getEchoFunction());
 }
Example #8
0
 public function __toString()
 {
     return Nife_Util::stringifyBlob($this);
 }
Example #9
0
 public function testEchoOutputBlob()
 {
     ob_start();
     $this->blob->writeTo(Nife_Util::getEchoFunction());
     $this->assertEquals("Some stuff\n", ob_get_clean());
 }