Files
RubyMotion/lib/motion/util/code_sign.rb
2014-10-20 16:53:19 +02:00

38 lines
1.1 KiB
Ruby

# encoding: utf-8
module Motion; module Util
module CodeSign
class << self
# @param [Boolean] valid_only
# Whether or not to include _only_ valid code sign identities.
#
# @return [String] The raw output from querying the `security` DB.
#
def query_security_db_for_identities(valid_only)
command = '/usr/bin/security -q find-identity -p codesigning'
command << ' -v' if valid_only
`#{command}`.strip
end
# @param [Boolean] valid_only
# Whether or not to include _only_ valid code sign identities.
#
# @return [Hash{String => String}] The UUIDs and names of the identities.
#
def identities(valid_only)
output = query_security_db_for_identities(valid_only)
Hash[*output.scan(/(\h{40})\s"(.+?)"/).flatten]
end
# @param [Boolean] valid_only
# Whether or not to include _only_ valid code sign identities.
#
# @return [Array<String>] The names of the identities.
#
def identity_names(valid_only)
identities(valid_only).values
end
end
end
end; end