当前位置: 首页>>代码示例>>PHP>>正文


PHP TestCase::getContext方法代码示例

本文整理汇总了PHP中TestCase::getContext方法的典型用法代码示例。如果您正苦于以下问题:PHP TestCase::getContext方法的具体用法?PHP TestCase::getContext怎么用?PHP TestCase::getContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestCase的用法示例。


在下文中一共展示了TestCase::getContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test

 public function test()
 {
     $privKey = hash('sha256', 'private key', true);
     $msg32 = hash('sha256', 'msg', true);
     $pub_t = '';
     /** @var resource $pub_t */
     $context = TestCase::getContext();
     // Create public key of our private key
     $this->assertEquals(1, secp256k1_ec_pubkey_create($context, $pub_t, $privKey));
     // Create recoverable signature
     $r_sig_t = '';
     /** @var resource $r_sig_t */
     $this->assertEquals(1, secp256k1_ecdsa_sign_recoverable($context, $r_sig_t, $msg32, $privKey));
     $this->assertEquals(SECP256K1_TYPE_RECOVERABLE_SIG, get_resource_type($r_sig_t));
     // Recover public key from the signature
     $r_pubkey_t = '';
     /** @var resource $r_pubkey_t */
     $this->assertEquals(1, secp256k1_ecdsa_recover($context, $r_pubkey_t, $r_sig_t, $msg32));
     // Compare the two public keys
     $sPubkey = '';
     $srPubkey = '';
     $this->assertEquals(1, secp256k1_ec_pubkey_serialize($context, $sPubkey, $pub_t, 0));
     $this->assertEquals(1, secp256k1_ec_pubkey_serialize($context, $srPubkey, $r_pubkey_t, 0));
     $this->assertEquals($sPubkey, $srPubkey);
     // Double check that serialize(sig) == serialize(parse(serialize(sig))
     $sSig = '';
     /** @var resource $sSig */
     $recid = '';
     secp256k1_ecdsa_recoverable_signature_serialize_compact($context, $r_sig_t, $sSig, $recid);
     $parsedSig = '';
     /** @var resource $parsedSig */
     $this->assertEquals(1, secp256k1_ecdsa_recoverable_signature_parse_compact($context, $parsedSig, $sSig, $recid));
     $sSigAgain = '';
     $recidAgain = '';
     secp256k1_ecdsa_recoverable_signature_serialize_compact($context, $parsedSig, $sSigAgain, $recidAgain);
     // Prepare expected DER sig
     $rl = 32;
     $r = substr($sSig, 0, 32);
     if (ord($sSig[0]) > 0x80) {
         $rl++;
         $r = "" . $r;
     }
     $sl = 32;
     $s = substr($sSig, 32, 32);
     if (ord($sSig[32]) > 0x80) {
         $sl++;
         $s = "" . $s;
     }
     $t = 4 + $rl + $sl;
     $der = "0" . chr($t) . "" . chr($rl) . $r . "" . chr($sl) . $s;
     $plain = '';
     /** @var resource $plain */
     // Test that conversion is successful
     $this->assertEquals(1, secp256k1_ecdsa_recoverable_signature_convert($context, $plain, $r_sig_t));
     // Test the converted sig's DER output matches what we expect
     $derSer = '';
     $this->assertEquals(1, secp256k1_ecdsa_signature_serialize_der($context, $derSer, $plain));
     $this->assertEquals($der, $derSer);
 }
开发者ID:afk11,项目名称:secp256k1-php,代码行数:59,代码来源:Secp256k1SignRecoverableTest.php

示例2: getErroneousTypeVectors

 public function getErroneousTypeVectors()
 {
     $context = TestCase::getContext();
     $msg32 = pack("H*", '03acc83ba10066e791d51e8a8eb90ec325feea7251cb8f979996848fff551d13');
     $sig = pack("H*", 'fe5fe404f3d8c21e1204a08c38ff3912d43c5a22541d2f1cdc4977cbcad240015a3b6e9040f62cacf016df4fef9412091592e4908e5e3a7bd2a42a4d1be01951');
     $s = '';
     $recid = 0;
     $this->assertEquals(1, secp256k1_ecdsa_recoverable_signature_parse_compact($context, $s, $sig, $recid));
     $array = array();
     $class = new Secp256k1EcdsaRecoverCompactTest();
     $resource = openssl_pkey_new();
     return array(array($context, $array, $s), array($context, $resource, $s), array($context, $class, $s), array($context, $msg32, $array), array($context, $msg32, $resource), array($context, $msg32, $class));
 }
开发者ID:afk11,项目名称:secp256k1-php,代码行数:13,代码来源:Secp256k1EcdsaRecoverCompactTest.php

示例3: testEcdsa

 /**
  * Testing return value 1
  */
 public function testEcdsa()
 {
     $context = TestCase::getContext();
     $priv1 = str_pad('', 32, "A");
     $priv2 = str_pad('', 32, "@");
     $expectedSecret = '238c14f420887f8e9bfa78bc9bdded1975f0bb6384e33b4ebbf7a8c776844aec';
     $pub1 = '';
     $pub2 = '';
     $this->assertEquals(1, secp256k1_ec_pubkey_create($context, $pub1, $priv1));
     $this->assertEquals(1, secp256k1_ec_pubkey_create($context, $pub2, $priv2));
     /**
      * @var resource $pub2
      * @var resource $pub1
      */
     $result = '';
     $this->assertEquals(1, secp256k1_ecdh($context, $result, $pub2, $priv1));
     $this->assertEquals(32, strlen($result));
     $this->assertEquals(pack("H*", $expectedSecret), $result);
 }
开发者ID:afk11,项目名称:secp256k1-php,代码行数:22,代码来源:Secp256k1EcdhTest.php


注:本文中的TestCase::getContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。