Sha256: a87ec5614146d929859f37d291b241f281db8e43de2a59db05d24b70ff5a28c5

Contents?: true

Size: 576 Bytes

Versions: 1

Compression:

Stored size: 576 Bytes

Contents

module Refcode

  class Encoder

    attr_accessor :secret, :salt

    def initialize
      yield self if block_given?
    end
    def encode val
      Base64URL.encode(encrypt(YAML.dump(val)))
    end
    def decode val
      YAML.load(decrypt(Base64URL.decode(val)))
    end

    private

    def encrypt val
      Encryptor.encrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv)
    end
    def decrypt val
      Encryptor.decrypt(:value => val, :key => @secret, :salt => @salt, :iv => iv)
    end
    def iv
      [@secret, @salt, 42].join
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
refcode-0.1.1 lib/refcode/encoder.rb