def encode_hex_secret secret
      # TODO(stevenle): Something further encodes the secret to a 64-char hex
      # string. For now, use adb logcat to figure out what the expected challenge
      # is. Eventually, make sure the encoding matches the server reference
      # implementation:
      #   http://code.google.com/p/google-tv-pairing-protocol/source/browse/src/com/google/polo/pairing/PoloChallengeResponse.java

      encoded_secret = [secret.to_i(16)].pack("N").unpack("cccc")[2..3].pack("c*")

      # Per "Polo Implementation Overview", section 6.1, client key material is
      # hashed first, followed by the server key material, followed by the nonce.
      digest = OpenSSL::Digest::Digest.new('sha256')
      digest << @gtv.ssl_client.cert.public_key.n.to_s(2)       # client modulus
      digest << @gtv.ssl_client.cert.public_key.e.to_s(2)       # client exponent
      digest << @gtv.ssl_client.peer_cert.public_key.n.to_s(2)  # server modulus
      digest << @gtv.ssl_client.peer_cert.public_key.e.to_s(2)  # server exponent

      digest << encoded_secret[encoded_secret.size / 2]
      return digest.digest
    end
def encode_hex_secret secret
      # TODO(stevenle): Something further encodes the secret to a 64-char hex
      # string. For now, use adb logcat to figure out what the expected challenge
      # is. Eventually, make sure the encoding matches the server reference
      # implementation:
      #   http://code.google.com/p/google-tv-pairing-protocol/source/browse/src/com/google/polo/pairing/PoloChallengeResponse.java

      encoded_secret = [secret.to_i(16)].pack("N").unpack("cccc")[2..3].pack("c*")

      # Per "Polo Implementation Overview", section 6.1, client key material is
      # hashed first, followed by the server key material, followed by the nonce.
      digest = OpenSSL::Digest::Digest.new('sha256')
      digest << @gtv.ssl_client.cert.public_key.n.to_s(2)       # client modulus
      digest << @gtv.ssl_client.cert.public_key.e.to_s(2)       # client exponent
      digest << @gtv.ssl_client.peer_cert.public_key.n.to_s(2)  # server modulus
      digest << @gtv.ssl_client.peer_cert.public_key.e.to_s(2)  # server exponent

      digest << encoded_secret[encoded_secret.size / 2]
      return digest.digest
    end
Encode the secret from the TV into an OpenSSL Digest

 @param [String] secret pairing code from the TV's screen
 @return [Digest] OpenSSL Digest containing the encoded secret