Parent

MetasploitDataModels::Base64Serializer

Constants

DEFAULT

The default for {default}

LOADERS

Deserializers for {load}

  1. Base64 decoding and then unmarshalling the value.

  2. Parsing the value as YAML.

  3. The raw value.

Attributes

default[W]

Public Class Methods

new(attributes={}) click to toggle source

@param attributes [Hash] attributes @option attributes [Object] :default ({}) Value to use for {default}.

# File lib/metasploit_data_models/base64_serializer.rb, line 66
def initialize(attributes={})
  attributes.assert_valid_keys(:default)

  @default = attributes.fetch(:default, DEFAULT)
end

Public Instance Methods

default() click to toggle source

Creates a duplicate of default value

@return

# File lib/metasploit_data_models/base64_serializer.rb, line 46
def default
  @default.dup
end
dump(value) click to toggle source

Serializes the value by marshalling the value and then base64 encodes the marshaled value.

@param value [Object] value to serialize @return [String]

# File lib/metasploit_data_models/base64_serializer.rb, line 56
def dump(value)
  # Always store data back in the Marshal format
  marshalled = Marshal.dump(value)
  base64_encoded = [ marshalled ].pack('m')

  base64_encoded
end
load(value) click to toggle source

Deserializes the value by either

  1. Base64 decoding and then unmarshalling the value.

  2. Parsing the value as YAML.

  3. Returns the raw value.

@param value [String] serialized value @return [Object]

@see default

# File lib/metasploit_data_models/base64_serializer.rb, line 81
def load(value)
  loaded = nil

  if value.blank?
    loaded = default
  else
    LOADERS.each do |loader|
      begin
        loaded = loader.call(value)
      rescue
        next
      else
        break
      end
    end
  end

  loaded
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.