コード例 #1
0
ファイル: IdentityUnitTest.php プロジェクト: sgoendoer/sonic
 public function testGID()
 {
     $key = "-----BEGIN PUBLIC KEY-----MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnDOhWIumc12Cf4O1AqAnnv/vCbsgoSqAhMwtvl+7Yjb+aPwuT+EoKN2mGNZ1GMrKZrqHNzkhzJCyLGCo/Zg4V95Xza4f8QxRUH/mOMp132VjvUKlnRNMEqE5hv85mtG5D4dTpkfu4wxxhCfND9bG3GmIoTMYjVGjm0947Zy+VWH1TI4dPVYTvDlwSEsbT5uXQySLBx2XkThynp+e+LGSsmga46LVkt5JUAjIgEstWXaMSJrofGenizw+Yf9tcjgYVDaYsWJVFO24pLkQkVNVt33zZREHECgVObWSJIRX2f/DMrC6pWbNgPdmwodI4dqezg+MvfZ+x+tLFtaquZBx0YH+45wpqy1txgxYUEPUJEsKy+0VxRZTu28j6mKpINQFw0OGMTtcQmZgvdf+JnJOKy0jFjO/CI3kod7SwW3cmTXSfp7KLbHN6BF4hrSpAhro3/2Pixa5LTIDhN1B1oNghbfQ6vXH9Ge8ZAS0G1q3jn/3zicoN+hCn3B8Bxx02Ere2laytnUCNz2HT+DlEtji4gFZEvou/TjjCrwKtTR0XTyUSiNkkG0xFSR0p+ghImz593t128r5I8iWRYCreQq2Z5a0PgcdC/BpdjPvpW2NGWuP4BRPJXO8ddsroi+kSjSqVZDKmtnP5HzpJxJVI/Clich40yaUM6nGVMSQAljGvB0CAwEAAQ==-----END PUBLIC KEY-----";
     $salt = "0b9357af0b74e6a4";
     $gid1 = '3Z51OUSP4UPXTEOOKSDXVZQLMYGNJQVY0SKYUKKGVT8QWD78T5';
     $gid2 = '2Z51OUSP4UPXTEOOKSDXVZQLMYGNJQVY0SKYUKKGVT8QWD78T5';
     $gid3 = '2Z51OUSP4UPXTEOOKSDXVZQLMYGNJQVY0';
     $gid4 = '2-Z51OUSP4UPXTEOOKSDXVZQLMYGNJQVY0SKYUKKGVT8QWD78T';
     $this->assertEquals($gid1, GID::createGID($key, $salt));
     $this->assertEquals(true, GID::isValid($gid1));
     $this->assertEquals(true, GID::verifyGID($key, $salt, $gid1));
     $this->assertNotEquals($gid2, GID::createGID($key, $salt));
     $this->assertTrue(GID::isValid($gid2));
     $this->assertFalse(GID::verifyGID($key, $salt, $gid2));
     $this->assertFalse(GID::isValid($gid3));
     $this->assertFalse(GID::isValid($gid4));
 }
コード例 #2
0
 /**
  * Builder method that creates the actual SocialRecord object
  * 
  * @throws SocialRecordFormatException
  * 
  * @return The SocialRecord (SocialRecord)
  */
 public function build()
 {
     if ($this->displayName == NULL) {
         throw new SocialRecordFormatException('SocialRecord: displayName must be specified for instantiation');
     }
     if ($this->profileLocation == NULL) {
         throw new SocialRecordFormatException('SocialRecord: profileLocation must be specified for instantiation');
     }
     if ($this->personalPublicKey == NULL) {
         throw new SocialRecordFormatException('SocialRecord: personalPublicKey must be specified for instantiation');
     }
     if ($this->accountPublicKey == NULL) {
         throw new SocialRecordFormatException('SocialRecord: accountPublicKey must be specified for instantiation');
     }
     if ($this->type == NULL) {
         throw new SocialRecordFormatException('SocialRecord: type must be specified for instantiation');
     }
     if ($this->type != SocialRecord::TYPE_PLATFORM && $this->type != SocialRecord::TYPE_USER) {
         throw new SocialRecordFormatException('SocialRecord: Invalid type value [' . $this->type . ']');
     }
     if ($this->salt == NULL) {
         $this->salt = Random::getRandom(SocialRecord::SALT_CHARS);
     }
     if ($this->datetime == NULL) {
         $this->datetime = XSDDateTime::getXSDDateTime();
     }
     if ($this->globalID == NULL) {
         $this->globalID = GID::createGID($this->personalPublicKey, $this->salt);
     }
     if (!GID::isValid($this->globalID)) {
         throw new SocialRecordFormatException('SocialRecord: Invalid globalID value [' . $this->globalID . ']');
     }
     if ($this->platformGID == NULL && $this->type == SocialRecord::TYPE_PLATFORM) {
         $this->platformGID = $this->globalID;
     }
     if ($this->platformGID == NULL) {
         throw new SocialRecordFormatException('SocialRecord: platformID must be specified for instantiation');
     }
     if (!GID::isValid($this->platformGID)) {
         throw new SocialRecordFormatException('SocialRecord: Invalid platformGID value [' . $this->platformGID . ']');
     }
     if ($this->keyRevocationList == NULL) {
         $this->keyRevocationList = array();
     }
     if ($this->active == NULL) {
         $this->active = 1;
     }
     return new SocialRecord($this);
 }