title: Object Identifier conversion ASN1
body: <p>I'm trying to implement custom object identifier of ASN1 in Python, these are sample test cases.</p>
  <pre><code>asn1_objectidentifier([1,2])
  asn1_objectidentifier([1,2,840])
  asn1_objectidentifier([1,2,840,5,1000000])
  asn1_objectidentifier([1,2,840,5,127,128,129])
  </code></pre>
  <p>What I couldn't manage to do is encoding value3 ... value n in base 128.
  This is my code so far</p>
  <pre><code>def asn1_objectidentifier(oid):
      first_octet = 40 * oid[0] + oid[1]
      rest = &quot;&quot;
      length = 1
      for v in range(2, len(oid)):
         if oid[v] &lt; 127:
            rest += chr(oid[v])
            length += 1
         else:
            rem = oid[v] / 128
            first = (rem * 128) ^ 1
            second = (oid[v] - first) * 128 ^ 0
            rest += int_to_bytestring(first)
            rest += int_to_bytestring(second)
            length += 2 
  
      rest = chr(first_octet) + rest
      return chr(0x06) + chr(length) + rest
  </code></pre>