Class: CocoaPodsKeys::KeyMaster
- Inherits:
-
Object
- Object
- CocoaPodsKeys::KeyMaster
- Defined in:
- lib/key_master.rb
Instance Attribute Summary collapse
-
#implementation ⇒ Object
Returns the value of attribute implementation.
-
#interface ⇒ Object
Returns the value of attribute interface.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #generate_data ⇒ Object
- #generate_implementation ⇒ Object
- #generate_interface ⇒ Object
-
#initialize(keyring, time = Time.now) ⇒ KeyMaster
constructor
A new instance of KeyMaster.
- #verify_keychain_integrity ⇒ Object
Constructor Details
#initialize(keyring, time = Time.now) ⇒ KeyMaster
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/key_master.rb', line 10 def initialize(keyring, time = Time.now) @time = time @keys = keyring.camel_cased_keys @name = keyring.code_name + 'Keys' if /^\d/ =~ @name @name = '_' + @name end @used_indexes = Set.new @indexed_keys = {} @data = generate_data @interface = generate_interface @implementation = generate_implementation end |
Instance Attribute Details
#implementation ⇒ Object
Returns the value of attribute implementation.
8 9 10 |
# File 'lib/key_master.rb', line 8 def implementation @implementation end |
#interface ⇒ Object
Returns the value of attribute interface.
8 9 10 |
# File 'lib/key_master.rb', line 8 def interface @interface end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/key_master.rb', line 8 def name @name end |
Instance Method Details
#generate_data ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/key_master.rb', line 25 def generate_data # guard method; raises error if something in application keychain # is nil. provides for better error message. verify_keychain_integrity # Generate a base64 hash string that is ~25 times the length of all keys @data_length = @keys.values.map(&:length).reduce(0, :+) * (20 + rand(10)) data = SecureRandom.base64(@data_length) data += '\\"' @data_length = data.length # Swap the characters within the hashed string with the characters from # the keyring values. Then store that index in a index-ed copy of the values. @keys.each do |key, value| @indexed_keys[key] = [] value.chars.each_with_index do |char, char_index| loop do if char == '"' index = data.delete('\\').length - 1 @indexed_keys[key][char_index] = index break else index = SecureRandom.random_number data.length unless @used_indexes.include?(index) data[index] = char @used_indexes << index @indexed_keys[key][char_index] = index break end end end end end data end |
#generate_implementation ⇒ Object
69 70 71 |
# File 'lib/key_master.rb', line 69 def generate_implementation render_erb('Keys.m.erb') end |
#generate_interface ⇒ Object
65 66 67 |
# File 'lib/key_master.rb', line 65 def generate_interface render_erb('Keys.h.erb') end |
#verify_keychain_integrity ⇒ Object
73 74 75 76 77 |
# File 'lib/key_master.rb', line 73 def verify_keychain_integrity if @keys.any? { |k, v| k.nil? || v.nil? } raise 'A key/value pair in the application keychain is nil.' end end |