コード例 #1
0
ファイル: Socket.php プロジェクト: mszula/php-newcamd
 public function receive($len = null)
 {
     if (!$len) {
         $len = $this->receive(2);
     }
     if ($len instanceof ServerMessage\Response\DataLength) {
         $len = $len->getLength();
     }
     if (socket_recv($this->socket, $data, $len, MSG_WAITALL) === false) {
         $this->error();
     }
     if (!$this->checkLength($data, $len)) {
         throw new SocketException('Read error ' . $len . ' bytes from server.', -1);
     }
     return ServerMessageFactory::create($data);
 }
コード例 #2
0
ファイル: Cipher.php プロジェクト: mszula/php-newcamd
 public function decrypt()
 {
     if (!$this->getMessage() instanceof ServerMessage\Crypt) {
         throw new CipherException('Can\'t decrypt ' . get_class($this->getMessage()) . '. Only ServerMessage\\Crypt is allowed.', 3);
     }
     $this->cipher->setIv($this->getMessage()->getRange($this->getMessage()->getLength() - 8, 8));
     $decrypted = new Byte();
     $decrypted->set('');
     $length = $this->getMessage()->getLength();
     for ($i = 0; $i < $length - 8; $i += self::DES_BLOCK_SIZE) {
         $range = $this->getMessage()->getRange($i, self::DES_BLOCK_SIZE);
         $decrypted->append($this->cipher->decrypt($range));
         $this->cipher->setIv($range);
     }
     if (!$this->checkChecksum($decrypted)) {
         throw new CipherException('Checksum failed. Possible incorrect 3DES key', 4);
     }
     // Todo: Obsługa sid caid, aktualnie wycinane
     $decrypted = $decrypted->getRange(10);
     return ServerMessageFactory::create($decrypted);
 }