static public void Clear() { if (session != null) { session.Dispose(); session = null; } if (le != null) { le.Dispose(); le = null; } session = new storageInfo(); le = new LE(); state = formState.NONE; modified = formModState.UNMODIFIED; }
static public storageInfo openStorage(Stream file) { Ber data = null; byte[] buf = null; storageInfo sess = new storageInfo(); sess.file = file; try { if (file.Length < 18) { pu(98); } if (file.Length > 99 * (1 << 20)) { pu(99); } try { buf = new byte[file.Length]; file.Read(buf, 0, (int)file.Length); data = new Ber(buf); } catch (Exception ex) { pu(100); } if (data.tClass != 0x3) { pu(97); } if (data.tag != 0xB183651C18E500) { pu(97); } if (data.childs.Count < 3) { pu(97); } if (data.childs[0].tag != (UInt64)BerTags.UTF8String) { pu(97); } if (Encoding.UTF8.GetString(data.childs[0].payload) != "shStorage") { pu(97); } if (data.childs[1].tag != (UInt64)BerTags.INTEGER) { pu(97); } if (data.childs[0].tClass != 0 || data.childs[1].tClass != 0) { pu(97); } if (data.childs[1].payloadLength == 1) { switch (data.childs[1].payload[0]) { case 1: if (data.childs.Count != 4) { pu(96); } if (data.childs[3].container || data.childs[3].tag != (UInt64)BerTags.OCTET_STRING || data.childs[3].tClass != (byte)BerClass.PRIVATE || data.childs[3].payloadLength != 32) { utils.pu(96); } if (!SHA256.Create().ComputeHash(data.childs[2].makeDer()).SequenceEqual(data.childs[3].payload)) { pu(96); } storageParse.parseVER1(sess, data.childs[2]); break; default: pu(100); break; } } else { pu(97); } if (data != null) { data.Dispose(); } return(sess); } catch (Exception ex) { if (data != null) { data.Dispose(); } sess.Dispose(); if (ex.Data.Contains("sh")) { switch ((int)ex.Data["sh"]) { case 96: throw new Exception("Файл поврежден."); case 97: throw new Exception("Файл не является хранилищем"); case 98: throw new Exception("Размер файла слишком мал, чтобы быть файлом программы."); case 99: throw new Exception("Размер файла слишком велик, чтобы быть файлом программы. Попробуте обновить программу и попробовать снова."); case 100: throw new Exception("Файл не поддерживается программой. Попробуте обновить программу и попробовать снова."); default: throw ex; } } else { throw ex; } } }