I have to convert the following code into Qt c++
So I need to understand what these lines to.
@key in this code is a pem key file contents by openssl
key = KEY+@key.public_key.to_der
-
so i think this is converting that key to der format and then combining it with KEY.
is it right? -
whats does this do? to_sizet(key.size)
As you can see the function returns [num].pack(‘V’). But i dont know wht does it do? I mean [num].pavck(‘V’). what is it? -
And whats does this mean. key.size is it the strlen of key?
def write_crx print "write crx..." if @verbose key = KEY+@key.public_key.to_der File.open(@crx, 'wb') do |file| file << MAGIC file << EXT_VERSION file << to_sizet(key.size) file << to_sizet(@sig.size) file << key file << @sig File.open(@zip, 'rb') do |zip| file << zip.read end end puts "done at \"#{@crx}\"" if @verbose end def to_sizet num return [num].pack('V') end
Well I have one more Question. Forgot to add last time.
what does this line do?
KEY = %w(30 81 9F 30 0D 06 09 2A 86 48 86 F7 0D 01 01 01 05 00 03 81 8D 00).map{|s| s.hex}.pack('C*')
Yes.
Well, just have a look at what the documentation on
Array#packsays. With theVmodifier, it just converts the array to a binary representation of a 32 bit unsigned integer type.Again, the Ruby documentation helps.
String#sizeis indeed the string length.%(…)defines an array where each of its entries, separated by whitespace is treated as a separate string.%w(one two)is essentially a shorthand for["one", "two"].After that, we have to look up (again in the documentation) the meanings of
Array#mapandString#hex.mapsimply applies an operation to each element of an array and creates a new array with the result. The operation iss.hex– that is, parse each of the strings as a hexadecimal number.The result is once again packed, this time using the
C*operation which, the documentation tells us, converts the numbers into their corresponding (unsigned) 8-bit character codes.In summary: that line converts the hexadecimal values into a string of their respective characters.
Afterthought: you should really install Ruby and play a bit with the interactive Ruby console,
irb. Keying in the above line already helps a lot: