Ejemplo n.º 1
0
 public static bool IsRoidStr(string inStr)
 {
     bool retval = false;
     MemoryStream ms = new MemoryStream();
     RelativeOid roid = new RelativeOid();
     roid.Encode(ms, inStr);
     ms.Close();
     retval = true;
     return retval;
 }
Ejemplo n.º 2
0
 public static bool EditNode(IWin32Window parent, Asn1Node aNode, bool enableTagEdit, bool pureHexMode)
 {
     byte[] val;
     byte[] data;
     FormNodeContentEditor ed = new FormNodeContentEditor();
     ed.aNode = aNode;
     MemoryStream ms = new MemoryStream();
     ed.checker = FormNodeContentEditor.DataChecker.None;
     ed.enableTagEdit = enableTagEdit;
     ed.pureHexMode = pureHexMode;
     if (
         ((aNode.Tag&Asn1Tag.TAG_MASK) == Asn1Tag.BIT_STRING) &&
         (aNode.ChildNodeCount<1))
     {
         ed.panelUnusedBits.Visible = true;
         ed.textBoxUnusedBits.Text = aNode.UnusedBits.ToString();
     }
     else
     {
         ed.panelUnusedBits.Visible = false;
     }
     if (pureHexMode)
     {
         ed.checker = DataChecker.Hex;
         ed.ShowDialog(parent);
         if (!ed.isOK) return false;
         data = Asn1Util.HexStrToBytes(ed.GetValueStr());
         aNode.Data = data;
     }
     else
     {
         byte[] oidVal;
         switch (aNode.Tag)
         {
             case Asn1Tag.OBJECT_IDENTIFIER:
                 ed.checker = DataChecker.Oid;
                 ed.ShowDialog(parent);
                 if (!ed.isOK) return false;
                 Oid xoid = new Oid();
                 xoid.Encode(ms, ed.GetValueStr());
                 ms.Position = 0;
                 oidVal = new byte[ms.Length];
                 ms.Read(oidVal, 0, (int)ms.Length);
                 ms.Close();
                 aNode.Data = oidVal;
                 break;
             case Asn1Tag.RELATIVE_OID:
                 ed.checker = DataChecker.Roid;
                 ed.ShowDialog(parent);
                 if (!ed.isOK) return false;
                 RelativeOid roid = new RelativeOid();
                 roid.Encode(ms, ed.GetValueStr());
                 ms.Position = 0;
                 oidVal = new byte[ms.Length];
                 ms.Read(oidVal, 0, (int)ms.Length);
                 ms.Close();
                 aNode.Data = oidVal;
                 break;
             case Asn1Tag.PRINTABLE_STRING:
             case Asn1Tag.IA5_STRING:
             case Asn1Tag.UNIVERSAL_STRING:
             case Asn1Tag.VISIBLE_STRING:
             case Asn1Tag.NUMERIC_STRING:
             case Asn1Tag.UTC_TIME:
             case Asn1Tag.GENERAL_STRING:
             case Asn1Tag.GENERALIZED_TIME:
                 ed.ShowDialog(parent);
                 if (!ed.isOK) return false;
                 val = Asn1Util.StringToBytes(ed.GetValueStr());
                 aNode.Data = val;
                 break;
             case Asn1Tag.UTF8_STRING:
                 ed.ShowDialog(parent);
                 if (!ed.isOK) return false;
                 UTF8Encoding u8 = new UTF8Encoding(false);
                 val = u8.GetBytes(ed.GetValueStr());
                 aNode.Data = val;
                 break;
             case Asn1Tag.BMPSTRING:
                 ed.ShowDialog(parent);
                 if (!ed.isOK) return false;
                 byte[] tmpval = Asn1Util.StringToBytes(ed.GetValueStr());
                 val = new byte[tmpval.Length*2];
                 for (int i = 0; i<tmpval.Length; i++)
                 {
                     val[i*2] = 0;
                     val[i*2+1] = tmpval[i];
                 }
                 aNode.Data = val;
                 break;
             case Asn1Tag.INTEGER:
             case Asn1Tag.BIT_STRING:
                 ed.checker = DataChecker.Hex;
                 ed.ShowDialog(parent);
                 if (!ed.isOK) return false;
                 aNode.UnusedBits = (byte)(Convert.ToUInt16(ed.textBoxUnusedBits.Text)%8);
                 data = Asn1Util.HexStrToBytes(ed.GetValueStr());
                 aNode.Data = data;
                 break;
             default:
                 if ((aNode.Tag & Asn1Tag.TAG_MASK) == 6) // Visible string for certificate
                 {
                     ed.ShowDialog(parent);
                     if (!ed.isOK) return false;
                     val = Asn1Util.StringToBytes(ed.GetValueStr());
                     aNode.Data = val;
                 }
                 else
                 {
                     ed.checker = DataChecker.Hex;
                     ed.ShowDialog(parent);
                     if (!ed.isOK) return false;
                     data = Asn1Util.HexStrToBytes(ed.GetValueStr());
                     aNode.Data = data;
                 }
                 break;
         };
     }
     return true;
 }