Example #1
0
 public function testFromBinary()
 {
     $originalObject = new Attributes();
     $sans = new SubjectAlternativeNames();
     $sans->addDomainName(new DNSName('corvespace.de'));
     $extensionRequest = new CertificateExtensions();
     $extensionRequest->addSubjectAlternativeNames($sans);
     $originalObject->addAttribute(OID::PKCS9_EXTENSION_REQUEST, $extensionRequest);
     $binaryData = $originalObject->getBinary();
     $parsedObject = Attributes::fromBinary($binaryData);
     $this->assertEquals($originalObject, $parsedObject);
 }
Example #2
0
 /**
  * @depends testFromBinary
  */
 public function testFromBinaryWithOffset()
 {
     $objectIdentifier = new ObjectIdentifier(OID::CERT_EXT_SUBJECT_ALT_NAME);
     $originalObject1 = new CertificateExtensions();
     $sans1 = new SubjectAlternativeNames();
     $sans1->addDomainName(new DNSName('corvespace.de'));
     $sans1->addIP(new IPAddress('192.168.0.1'));
     $originalObject1->addSubjectAlternativeNames($sans1);
     $originalObject2 = new CertificateExtensions();
     $sans2 = new SubjectAlternativeNames();
     $sans2->addDomainName(new DNSName('google.com'));
     $originalObject2->addSubjectAlternativeNames($sans2);
     $binaryData = $originalObject1->getBinary();
     $binaryData .= $originalObject2->getBinary();
     $offset = 0;
     $parsedObject = CertificateExtensions::fromBinary($binaryData, $offset);
     $this->assertEquals($originalObject1, $parsedObject);
     $offsetAfterFirstObject = $sans1->getObjectLength() + $objectIdentifier->getObjectLength() + 2 + 2 + 2;
     $this->assertEquals($offsetAfterFirstObject, $offset);
     $parsedObject = CertificateExtensions::fromBinary($binaryData, $offset);
     $this->assertEquals($originalObject2, $parsedObject);
     $this->assertEquals($offsetAfterFirstObject + $sans2->getObjectLength() + $objectIdentifier->getObjectLength() + 2 + 2 + 2, $offset);
 }
 /**
  * @depends testFromBinary
  */
 public function testFromBinaryWithOffset()
 {
     $originalObject1 = new SubjectAlternativeNames();
     $originalObject1->addDomainName(new DNSName('corvespace.de'));
     $originalObject1->addIP(new IPAddress('192.168.0.1'));
     $originalObject1->addIP(new IPAddress('10.218.0.1'));
     $originalObject2 = new SubjectAlternativeNames();
     $originalObject2->addDomainName(new DNSName('google.com'));
     $binaryData = $originalObject1->getBinary();
     $binaryData .= $originalObject2->getBinary();
     $offset = 0;
     $parsedObject = SubjectAlternativeNames::fromBinary($binaryData, $offset);
     $this->assertEquals($originalObject1, $parsedObject);
     $this->assertEquals(31, $offset);
     $parsedObject = SubjectAlternativeNames::fromBinary($binaryData, $offset);
     $this->assertEquals($originalObject2, $parsedObject);
     $this->assertEquals(47, $offset);
 }