def parse(buffer, offset = 0)
      return 0 if buffer.nil? || (buffer == '') || (buffer.length <= MAGIC_HEADER_SIZE + 2)

      # Symmetric Encryption Header
      #
      # Consists of:
      #    4 Bytes: Magic Header Prefix: @Enc
      #    1 Byte:  The version of the cipher used to encrypt the header.
      #    1 Byte:  Flags:
      #       Bit 1: Whether the data is compressed
      #       Bit 2: Whether the IV is included
      #       Bit 3: Whether the Key is included
      #       Bit 4: Whether the Cipher Name is included
      #       Bit 5: Future use
      #       Bit 6: Future use
      #       Bit 7: Future use
      #       Bit 8: Future use
      #    2 Bytes: IV Length (little endian), if included.
      #      IV in binary form.
      #    2 Bytes: Key Length (little endian), if included.
      #      Key in binary form
      #    2 Bytes: Cipher Name Length (little endian), if included.
      #      Cipher name it UTF8 text

      buffer.force_encoding(SymmetricEncryption::BINARY_ENCODING)
      header = buffer.byteslice(offset, MAGIC_HEADER_SIZE)
      return 0 unless header == MAGIC_HEADER

      offset += MAGIC_HEADER_SIZE

      # Remove header and extract flags
      self.version = buffer.getbyte(offset)
      offset      += 1

      unless cipher
        raise(
          SymmetricEncryption::CipherError,
          "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers"
        )
      end

      flags   = buffer.getbyte(offset)
      offset += 1

      self.compress = (flags & FLAG_COMPRESSED) != 0

      if (flags & FLAG_IV) != 0
        self.iv, offset = read_string(buffer, offset)
      else
        self.iv = nil
      end

      if (flags & FLAG_KEY) != 0
        encrypted_key, offset = read_string(buffer, offset)
        self.key              = cipher.binary_decrypt(encrypted_key)
      else
        self.key = nil
      end

      if (flags & FLAG_CIPHER_NAME) != 0
        self.cipher_name, offset = read_string(buffer, offset)
      else
        self.cipher_name = nil
      end

      if (flags & FLAG_AUTH_TAG) != 0
        self.auth_tag, offset = read_string(buffer, offset)
      else
        self.auth_tag = nil
      end

      offset
    end
def parse(buffer, offset = 0)
      return 0 if buffer.nil? || (buffer == '') || (buffer.length <= MAGIC_HEADER_SIZE + 2)

      # Symmetric Encryption Header
      #
      # Consists of:
      #    4 Bytes: Magic Header Prefix: @Enc
      #    1 Byte:  The version of the cipher used to encrypt the header.
      #    1 Byte:  Flags:
      #       Bit 1: Whether the data is compressed
      #       Bit 2: Whether the IV is included
      #       Bit 3: Whether the Key is included
      #       Bit 4: Whether the Cipher Name is included
      #       Bit 5: Future use
      #       Bit 6: Future use
      #       Bit 7: Future use
      #       Bit 8: Future use
      #    2 Bytes: IV Length (little endian), if included.
      #      IV in binary form.
      #    2 Bytes: Key Length (little endian), if included.
      #      Key in binary form
      #    2 Bytes: Cipher Name Length (little endian), if included.
      #      Cipher name it UTF8 text

      buffer.force_encoding(SymmetricEncryption::BINARY_ENCODING)
      header = buffer.byteslice(offset, MAGIC_HEADER_SIZE)
      return 0 unless header == MAGIC_HEADER

      offset += MAGIC_HEADER_SIZE

      # Remove header and extract flags
      self.version = buffer.getbyte(offset)
      offset      += 1

      unless cipher
        raise(
          SymmetricEncryption::CipherError,
          "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers"
        )
      end

      flags   = buffer.getbyte(offset)
      offset += 1

      self.compress = (flags & FLAG_COMPRESSED) != 0

      if (flags & FLAG_IV) != 0
        self.iv, offset = read_string(buffer, offset)
      else
        self.iv = nil
      end

      if (flags & FLAG_KEY) != 0
        encrypted_key, offset = read_string(buffer, offset)
        self.key              = cipher.binary_decrypt(encrypted_key)
      else
        self.key = nil
      end

      if (flags & FLAG_CIPHER_NAME) != 0
        self.cipher_name, offset = read_string(buffer, offset)
      else
        self.cipher_name = nil
      end

      if (flags & FLAG_AUTH_TAG) != 0
        self.auth_tag, offset = read_string(buffer, offset)
      else
        self.auth_tag = nil
      end

      offset
    end
Returns [Integer] the offset within the buffer of the data after the header has been read.

 Returns 0 if no header is present