Sha256: 254f57a3b89bf72a5c444624d65a794cd690da5b1ac5ff4af0a7d1718b97f31e

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module Wework
  class Provider
    include Wework::Cipher

    attr_accessor :corp_id, :provider_secret, :encoding_aes_key, :token

    def initialize(options={})
      @corp_id = options[:corp_id]
      @provider_secret = options[:provider_secret]
      @encoding_aes_key = options[:encoding_aes_key]
      @token = options[:token]
    end

    def msg_decrypt msg
      unpack(decrypt(Base64.decode64(msg), self.encoding_aes_key))[0]
    end

    def msg_encrypt msg
      Base64.strict_encode64(encrypt(pack(msg, self.corp_id), self.encoding_aes_key))
    end

    def signature(timestamp, nonce, encrypt)
      array = [self.token, timestamp, nonce]
      array << encrypt unless encrypt.nil?
      dev_msg_signature = array.compact.collect(&:to_s).sort.join
      Digest::SHA1.hexdigest(dev_msg_signature)
    end

    def generate_xml(msg, timestamp, nonce)
      encrypt = msg_encrypt(msg)
      {
        Encrypt: encrypt,
        MsgSignature: signature(timestamp, nonce, encrypt),
        TimeStamp: timestamp,
        Nonce: nonce
      }.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wework-0.3.4 lib/wework/provider.rb
wework-0.3.3 lib/wework/provider.rb
wework-0.3.2 lib/wework/provider.rb
wework-0.3.1 lib/wework/provider.rb
wework-0.3.0 lib/wework/provider.rb