Example #1
0
 /**
  * Perform Bit-String-to-Octet-String Conversion.
  *
  * Defined in SEC 1 section 2.3.1.
  *
  * @param BitString $bs
  * @throws \RuntimeException
  * @return OctetString
  */
 public static function bitStringToOctetString(BitString $bs)
 {
     $str = $bs->string();
     if ($bs->unusedBits()) {
         // @todo pad string
         throw new \RuntimeException("Unaligned bitstrings to supported");
     }
     return new OctetString($str);
 }
Example #2
0
File: Flags.php Project: sop/asn1
 /**
  * Initialize from BitString.
  *
  * @param BitString $bs
  * @param int $width
  * @return self
  */
 public static function fromBitString(BitString $bs, $width)
 {
     $num_bits = $bs->numBits();
     $num = gmp_import($bs->string(), 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
     $num >>= $bs->unusedBits();
     if ($num_bits < $width) {
         $num <<= $width - $num_bits;
     }
     return new self(gmp_strval($num, 10), $width);
 }
Example #3
0
 protected static function _fromDER($data, $critical)
 {
     return new self($critical, Flags::fromBitString(BitString::fromDER($data), 9)->number());
 }
Example #4
0
 /**
  * Get unique identifier as a string.
  *
  * @return string
  */
 public function string()
 {
     return $this->_uid->string();
 }