コード例 #1
0
 /**
  * Constructor
  *
  * @param   io.archive.zip.ZipArchiveWriter writer
  * @param   io.archive.zip.ZipFileEntry file
  */
 public function __construct(ZipArchiveWriter $writer, ZipFileEntry $file)
 {
     $this->writer = $writer;
     $this->file = $file;
     $this->data = NULL;
     $this->md = CRC32::digest();
 }
コード例 #2
0
 /**
  * Constructor
  *
  * @param   io.streams.OutputStream out
  * @param   int level default 6
  * @throws  lang.IllegalArgumentException if the level is not between 0 and 9
  */
 public function __construct(OutputStream $out, $level = 6)
 {
     if ($level < 0 || $level > 9) {
         throw new IllegalArgumentException('Level ' . $level . ' out of range [0..9]');
     }
     // Write GZIP format header:
     // * ID1, ID2 (Identification, \x1F, \x8B)
     // * CM       (Compression Method, 8 = deflate)
     // * FLG      (Flags, use 0)
     // * MTIME    (Modification time, Un*x timestamp)
     // * XFL      (Extra flags, 2 = compressor used maximum compression)
     // * OS       (Operating system, 255 = unknown)
     $out->write(pack('CCCCVCC', 0x1f, 0x8b, 8, 0, time(), 2, 255));
     // Now, convert stream to file handle and append deflating filter
     $this->out = Streams::writeableFd($out);
     if (!($this->filter = stream_filter_append($this->out, 'zlib.deflate', STREAM_FILTER_WRITE, $level))) {
         fclose($this->out);
         $this->out = NULL;
         throw new IOException('Could not append stream filter');
     }
     $this->md = CRC32::digest();
 }
コード例 #3
0
 /**
  * Returns a checksum for a given input string
  *
  * @param   string data
  * @return  security.checksum.Checksum
  */
 protected function checksumOf($data)
 {
     return CRC32::fromString($data)->getValue();
 }
コード例 #4
0
 /**
  * Prepare data to be sent
  *
  * @param   org.nagios.nsca.NscaMessage message
  * @return  string
  */
 public function prepare(NscaMessage $message)
 {
     // Calculate CRC32 checksum, then build the final packet with the sig
     // and encrypt it using defined crypt method
     return $this->encrypt($this->pack(CRC32::fromString($this->pack(0, $message))->asInt32(), $message));
 }
コード例 #5
0
 private static function generateSerializationSignature(Clazz $instanceType, CRC32 $crc, SerializationPolicy $policy)
 {
     $crc->update(self::getSerializedTypeName($instanceType));
     if (self::excludeImplementationFromSerializationSignature($instanceType)) {
         return;
     }
     $customSerializer = self::hasCustomFieldSerializer($instanceType);
     if (!is_null($customSerializer)) {
         self::generateSerializationSignature($customSerializer, $crc, $policy);
     } else {
         if ($instanceType->isArray()) {
             self::generateSerializationSignature($instanceType->getComponentType(), $crc, $policy);
         } else {
             if (!$instanceType->isPrimitive()) {
                 $fields = self::applyFieldSerializationPolicy($instanceType);
                 $clientFieldNames = $policy->getClientFieldNamesForEnhancedClass($instanceType);
                 foreach ($fields as $field) {
                     assert(!is_null($field));
                     /**
                      * If clientFieldNames is non-null, use only the fields listed there
                      * to generate the signature.  Otherwise, use all known fields.
                      */
                     if (is_null($clientFieldNames) || $clientFieldNames->contains($field->getName())) {
                         $crc->update($field->getName());
                         $crc->update(self::getSerializedTypeName($field->getType()));
                     }
                 }
                 $superClass = $instanceType->getSuperClass();
                 if (!is_null($superClass)) {
                     self::generateSerializationSignature($superClass, $crc, $policy);
                 }
             }
         }
     }
 }
コード例 #6
0
 /**
  * Create a new checksum from a file object
  *
  * @param   io.File file
  * @return  security.checksum.CRC32
  */
 public static function fromFile($file)
 {
     return CRC32::fromString(FileUtil::getContents($file));
 }