Sha256: 1ec7fbfdc9f577b66c4ace0a325ef4fac1d011fc77ed52d3245abcb82ac9294a
Contents?: true
Size: 1.67 KB
Versions: 5
Compression:
Stored size: 1.67 KB
Contents
#encoding UTF-8 require 'base64' require 'openssl' require 'date' module Fernet # Internal: Generates Fernet tokens class Generator # Internal: Returns the token's message attr_accessor :message # Internal: Initializes a generator # # opts - a hash containing the following keys: # * secret - a string containing a secret, optionally Base64 encoded # * message - the message def initialize(opts) @secret = opts.fetch(:secret) @message = opts[:message] @iv = opts[:iv] @now = opts[:now] end # Internal: generates a secret token # # Yields itself, useful for setting or overriding the message # # Examples # # generator = Generator.new(secret: some_secret) # token = generator.generate do |g| # g.message = 'this is my message' # end # # generator = Generator.new(secret: some_secret, # message: 'this is my message') # token = generator.generate # # Returns the token as a string def generate yield self if block_given? token = Token.generate(secret: @secret, message: @message, iv: @iv, now: @now) token.to_s end # Public: string representation of this generator, masks secret to avoid # leaks def inspect "#<Fernet::Generator @secret=[masked] @message=#{@message.inspect}>" end alias to_s inspect # Deprecated: used to set the message def data=(message) puts "[WARNING] 'data=' is deprecated, use 'message=' instead" @message = message end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
fernet-2.3 | lib/fernet/generator.rb |
fernet-2.2 | lib/fernet/generator.rb |
fernet-2.1.1 | lib/fernet/generator.rb |
fernet-2.1 | lib/fernet/generator.rb |
fernet-2.0 | lib/fernet/generator.rb |