title: What's the proper way to extract unexported fields from a Golang type?
body: <p>I'm trying to take an SSH public key (x.crypto.ssh.PublicKey, generated by parsing <code>authorized_keys</code>) and extract a plain old <code>crypto.rsa.PublicKey</code> from it (I know the key is of type <code>ssh-rsa</code>).  That means, in ssh-land, the key is of (unexported) type <code>rsaPublicKey</code>.</p>
  
  <p>By using either <code>reflect.Interface()</code> or plain old <code>fmt.Sprintf("%v")</code> I can get a value that looks like:</p>
  
  <pre><code>&amp;{133141753607255377833524803712241410600224583899447743985716492314976605735038858392516407436607315136967439536840885454950028631410155683051419836325912444338003188332463816050354540934271243064035037856360864190161298769948076508355604915775510460445701536855931828420791030023079646791573156484306628882221 35}
  </code></pre>
  
  <p>I know, by reading the ssh package source, that <code>ssh.rsaPublickey</code> is in fact defined as the type I want:</p>
  
  <pre><code>type rsaPublicKey rsa.PublicKey
  </code></pre>
  
  <p>and therefore this value is already the thing I want.  (In fact, I can, using <code>"%+v"</code>, even see that its fields are (of course) named <code>N</code> and <code>E</code>.)</p>
  
  <p>My problem is that I don't know a better way to make Go believe that this is in fact an <code>rsa.PublicKey</code> than to extract each of those numbers into strings with <code>fmt.Sscan</code>, and then convert into <code>big.Int</code> and <code>int</code>, respectively, and then use those two values I just got as the modulus and exponent to create a new <code>rsa.PublicKey</code>.</p>
  
  <p>That works, but seems incredibly nasty.  I get that since it's unexported, there's probably no direct route, but surely there's a better way to get the fields than by reconverting their printable representations.</p>
  
  <p><code>ssh.PublicKey</code> does have a <code>Marshal()</code> function, but that gives me the wire-format representation, and if I go through there, well, I guess it avoids abusing the type system, but I'd just end up writing my own byte-stream-to-big-Int-to-RSA converter there, which doesn't seem like it really helps.  At that point I might just as well start with the <code>authorized_keys</code> file and parse it myself, and that seems dumb too.</p>
  
  <p>What's the right way to do this?</p>