public OutStream writeNext(Uri path, DateTime modifyTime) { if (m_zipOut == null) { throw UnsupportedErr.make("Zip not opened for writing").val; } if (path.frag() != null) { throw ArgErr.make("Path must not contain fragment: " + path).val; } if (path.queryStr() != null) { throw ArgErr.make("Path must not contain query: " + path).val; } try { string zipPath = path.ToString(); if (zipPath.StartsWith("/")) { zipPath = zipPath.Substring(1); } ZipEntry entry = new ZipEntry(zipPath); entry.DateTime = new System.DateTime(modifyTime.dotnet()); m_zipOut.PutNextEntry(entry); return(new ZipSysOutStream(m_zipOut)); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
public void ordered(bool v) { modify(); if (m_map.Count != 0) { throw UnsupportedErr.make("Map not empty").val; } if (v && caseInsensitive()) { throw UnsupportedErr.make("Map cannot be caseInsensitive and ordered").val; } if (ordered() == v) { return; } if (v) { m_map = new OrderedDictionary(); } else { m_map = new Hashtable(); } }
public new static UnsupportedErr make(string msg, Err cause) { UnsupportedErr err = new UnsupportedErr(); make_(err, msg, cause); return(err); }
public void caseInsensitive(bool v) { modify(); if (m_type.m_k != Sys.StrType) { throw UnsupportedErr.make("Map not keyed by string: " + m_type).val; } if (m_map.Count != 0) { throw UnsupportedErr.make("Map not empty").val; } if (v && ordered()) { throw UnsupportedErr.make("Map cannot be caseInsensitive and ordered").val; } if (this.m_caseInsensitive == v) { return; } this.m_caseInsensitive = v; if (m_caseInsensitive) { m_map = new Hashtable(new CIEqualityComparer()); } else { m_map = new Hashtable(); } }
public virtual Type parameterize(Map pars) { if (this == Sys.ListType) { Type v = (Type)pars.get(FanStr.m_ascii['V']); if (v == null) { throw ArgErr.make("List.parameterize - V undefined").val; } return(v.toListOf()); } if (this == Sys.MapType) { Type v = (Type)pars.get(FanStr.m_ascii['V']); Type k = (Type)pars.get(FanStr.m_ascii['K']); if (v == null) { throw ArgErr.make("Map.parameterize - V undefined").val; } if (k == null) { throw ArgErr.make("Map.parameterize - K undefined").val; } return(new MapType(k, v)); } if (this == Sys.FuncType) { Type r = (Type)pars.get(FanStr.m_ascii['R']); if (r == null) { throw ArgErr.make("Map.parameterize - R undefined").val; } ArrayList p = new ArrayList(); for (int i = 'A'; i <= 'H'; ++i) { Type x = (Type)pars.get(FanStr.m_ascii[i]); if (x == null) { break; } p.Add(x); } return(new FuncType((Type[])p.ToArray(System.Type.GetType("Fan.Sys.Type")), r)); } throw UnsupportedErr.make("not generic: " + this).val; }
public bool finish() { if (m_zipOut == null) { throw UnsupportedErr.make("Zip not opened for writing").val; } try { m_zipOut.Finish(); return(true); } catch (System.IO.IOException) { return(false); } }
public virtual Long readBuf(Buf buf, long n) { try { return(m_in.readBuf(buf, n)); } catch (System.NullReferenceException e) { if (m_in == null) { throw UnsupportedErr.make(@typeof().qname() + " wraps null InStream").val; } else { throw e; } } }
public virtual InStream unread(long n) { try { m_in.unread(n); return(this); } catch (System.NullReferenceException e) { if (m_in == null) { throw UnsupportedErr.make(@typeof().qname() + " wraps null InStream").val; } else { throw e; } } }
public virtual OutStream writeBuf(Buf buf, long n) { try { m_out.writeBuf(buf, n); return(this); } catch (System.NullReferenceException e) { if (m_out == null) { throw UnsupportedErr.make(@typeof().qname() + " wraps null OutStream").val; } else { throw e; } } }
public File readNext() { if (m_zipIn == null) { throw UnsupportedErr.make("Zip not opened for reading").val; } try { ZipEntry entry = m_zipIn.GetNextEntry(); if (entry == null) { return(null); } return(new ZipEntryFile(this, entry)); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
////////////////////////////////////////////////////////////////////////// // GZIP ////////////////////////////////////////////////////////////////////////// public static OutStream gzipOutStream(OutStream o) { throw UnsupportedErr.make("Zip.gzipOutStream").val; }
public override Buf toDigest(string algorithm) { throw UnsupportedErr.make().val; }
public override void encode(char ch, InStream input) { throw UnsupportedErr.make("binary write on StrBuf output").val; }
////////////////////////////////////////////////////////////////////////// // Base64 ////////////////////////////////////////////////////////////////////////// public virtual string toBase64() { throw UnsupportedErr.make(@typeof() + ".toBase64").val; }
public override void capacity(long x) { throw UnsupportedErr.make("mmap capacity fixed").val; }
public override Buf hmac(string algorithm, Buf keyBuf) { // get digest algorthim string alg = algorithm; if (alg == "SHA-1") { alg = "SHA1"; // to make .NET happy } HashAlgorithm ha = HashAlgorithm.Create(alg); if (ha == null) { throw ArgErr.make("Unknown digest algorthm: " + algorithm).val; } // get secret key bytes int blockSize = 64; byte[] keyBytes = null; int keySize = 0; try { // get key bytes MemBuf keyMemBuf = (MemBuf)keyBuf; keyBytes = keyMemBuf.m_buf; keySize = keyMemBuf.m_size; // key is greater than block size we hash it first if (keySize > blockSize) { keyBytes = ha.ComputeHash(keyBytes, 0, keySize); keySize = keyBytes.Length; } } catch (System.InvalidCastException) { throw UnsupportedErr.make("key parameter must be memory buffer").val; } // RFC 2104: // ipad = the byte 0x36 repeated B times // opad = the byte 0x5C repeated B times // H(K XOR opad, H(K XOR ipad, text)) MemBuf acc = new MemBuf(1024); // inner digest: H(K XOR ipad, text) for (int i = 0; i < blockSize; ++i) { if (i < keySize) { acc.write((byte)(keyBytes[i] ^ 0x36)); } else { acc.write((byte)0x36); } } acc.pipeFrom(m_buf, 0, m_size); byte[] innerDigest = ha.ComputeHash(acc.m_buf, 0, acc.m_size); // outer digest: H(K XOR opad, innerDigest) acc.clear(); for (int i = 0; i < blockSize; ++i) { if (i < keySize) { acc.write((byte)(keyBytes[i] ^ 0x5C)); } else { acc.write((byte)0x5C); } } acc.pipeFrom(innerDigest, 0, innerDigest.Length); // return result return(new MemBuf(ha.ComputeHash(acc.m_buf, 0, acc.m_size))); }
public static void make_(UnsupportedErr self, string msg) { make_(self, msg, null); }
public static new UnsupportedErr make(string msg, Err cause) { UnsupportedErr err = new UnsupportedErr(); make_(err, msg, cause); return err; }
public static void make_(UnsupportedErr self) { make_(self, null); }
public override OutStream writeBuf(Buf buf, long n) { throw UnsupportedErr.make("binary write on StrBuf output").val; }
public virtual Buf hmac(String algorithm, Buf key) { throw UnsupportedErr.make(@typeof() + ".hmac").val; }
////////////////////////////////////////////////////////////////////////// // Digest ////////////////////////////////////////////////////////////////////////// public virtual Buf toDigest(string algorithm) { throw UnsupportedErr.make(@typeof() + ".toDigest").val; }
public static InStream gzipInStream(InStream i) { throw UnsupportedErr.make("Zip.gzipInStream").val; }
public override sealed string toHex() { throw UnsupportedErr.make().val; }
////////////////////////////////////////////////////////////////////////// // OutStream ////////////////////////////////////////////////////////////////////////// public override OutStream w(int v) { throw UnsupportedErr.make("binary write on StrBuf output").val; }
public override Buf mmap(string mode, long pos, Long size) { throw UnsupportedErr.make("ZipEntryFile.mmap").val; }
public override string promptPassword(string msg) { // TODO throw UnsupportedErr.make().val; }
////////////////////////////////////////////////////////////////////////// // Hex ////////////////////////////////////////////////////////////////////////// public virtual string toHex() { throw UnsupportedErr.make(@typeof() + ".toHex").val; }
public static void make_(UnsupportedErr self, string msg, Err cause) { Err.make_(self, msg, cause); }
public override File plus(Uri uri, bool checkSlash) { // TODO throw UnsupportedErr.make("ZipEntryFile.plus").val; }