public void WriteZigZag(long value) { var diff = value - lastSigned; writer.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(diff)); lastSigned = value; }
private SNode[] ReadAllNodes() { var allNodes = new SNode[nodesCount]; Flush(); stream.Position = 0; var id = 0L; var lat = 0; var lon = 0; for (var i = 0; i < allNodes.Length; i++) { var inc = EncodeHelpers.DecodeZigZag(reader.Read7BitEncodedInt()); if (inc == 0) { throw new InvalidOperationException("Unexpected end of nodes."); } id += inc; lat += (int)EncodeHelpers.DecodeZigZag(reader.Read7BitEncodedInt()); lon += (int)EncodeHelpers.DecodeZigZag(reader.Read7BitEncodedInt()); allNodes[i] = new SNode { Id = id, Lat = lat, Lon = lon }; } return(allNodes); }
public sealed override byte[] Encrypt(CmsRecipientCollection recipients, ContentInfo contentInfo, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes) { using (SafeCryptMsgHandle hCryptMsg = EncodeHelpers.CreateCryptMsgHandleToEncode(recipients, contentInfo.ContentType, contentEncryptionAlgorithm, originatorCerts, unprotectedAttributes)) { byte[] encodedContent; if (contentInfo.ContentType.Value.Equals(Oids.Pkcs7Data, StringComparison.OrdinalIgnoreCase)) { unsafe { byte[] content = contentInfo.Content; fixed(byte *pContent = content) { DATA_BLOB blob = new DATA_BLOB((IntPtr)pContent, (uint)(content.Length)); encodedContent = Interop.Crypt32.CryptEncodeObjectToByteArray(CryptDecodeObjectStructType.X509_OCTET_STRING, &blob); } } } else { encodedContent = contentInfo.Content; } if (encodedContent.Length > 0) { if (!Interop.Crypt32.CryptMsgUpdate(hCryptMsg, encodedContent, encodedContent.Length, fFinal: true)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } } byte[] encodedMessage = hCryptMsg.GetMsgParamAsByteArray(CryptMsgParamType.CMSG_CONTENT_PARAM); return(encodedMessage); } }
public static void WriteTo(this BoundingRect rect, BinaryWriter writer) { writer.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(rect.MinLat)); writer.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(rect.MinLon)); writer.Write7BitEncodedInt(rect.MaxLat - rect.MinLat); writer.Write7BitEncodedInt(rect.MaxLon - rect.MinLon); }
public sealed unsafe override byte[] Encrypt(CmsRecipientCollection recipients, ContentInfo contentInfo, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes) { using (SafeCryptMsgHandle hCryptMsg = EncodeHelpers.CreateCryptMsgHandleToEncode(recipients, contentInfo.ContentType, contentEncryptionAlgorithm, originatorCerts, unprotectedAttributes)) { byte[] encodedContent; if (contentInfo.ContentType.Value !.Equals(Oids.Pkcs7Data, StringComparison.OrdinalIgnoreCase)) { encodedContent = PkcsHelpers.EncodeOctetString(contentInfo.Content); }
public sealed unsafe override byte[] Encrypt(CmsRecipientCollection recipients, ContentInfo contentInfo, AlgorithmIdentifier contentEncryptionAlgorithm, X509Certificate2Collection originatorCerts, CryptographicAttributeObjectCollection unprotectedAttributes) { using (SafeCryptMsgHandle hCryptMsg = EncodeHelpers.CreateCryptMsgHandleToEncode(recipients, contentInfo.ContentType, contentEncryptionAlgorithm, originatorCerts, unprotectedAttributes)) { byte[] encodedContent; if (contentInfo.ContentType.Value.Equals(Oids.Pkcs7Data, StringComparison.OrdinalIgnoreCase)) { unsafe { byte[] content = contentInfo.Content; fixed(byte *pContent = content) { DATA_BLOB blob = new DATA_BLOB((IntPtr)pContent, (uint)(content.Length)); encodedContent = Interop.Crypt32.CryptEncodeObjectToByteArray(CryptDecodeObjectStructType.X509_OCTET_STRING, &blob); } } } else { encodedContent = contentInfo.Content; if (encodedContent.Length > 0) { // Windows will throw if it encounters indefinite length encoding. // Let's reencode if that is the case ReencodeIfUsingIndefiniteLengthEncodingOnOuterStructure(ref encodedContent); } } if (encodedContent.Length > 0) { // Pin to avoid copy during heap compaction fixed(byte *pinnedContent = encodedContent) { try { if (!Interop.Crypt32.CryptMsgUpdate(hCryptMsg, encodedContent, encodedContent.Length, fFinal: true)) { throw Marshal.GetLastWin32Error().ToCryptographicException(); } } finally { if (!object.ReferenceEquals(encodedContent, contentInfo.Content)) { Array.Clear(encodedContent, 0, encodedContent.Length); } } } } byte[] encodedMessage = hCryptMsg.GetMsgParamAsByteArray(CryptMsgParamType.CMSG_CONTENT_PARAM); return(encodedMessage); } }
public WayInfo FindWayInfo(ulong id) { var offsetIndex = FindBlockIndex(id); if (offsetIndex < 0) { return(null); } var offset = offsets[offsetIndex].Offset; infoStream.Position = offset; var offsetLimit = offsetIndex < offsets.Count - 1 ? offsets[offsetIndex + 1].Offset : infoLength; while (infoStream.Position < offsetLimit) { var cid = infoReader.Read7BitEncodedInt(); if (cid == id) { var minLat = infoReader.ReadInt32(); var minLon = infoReader.ReadInt32(); var midLat = (int)EncodeHelpers.DecodeZigZag(infoReader.Read7BitEncodedInt()) + minLat; var midLon = (int)EncodeHelpers.DecodeZigZag(infoReader.Read7BitEncodedInt()) + minLon; var maxLat = (int)EncodeHelpers.DecodeZigZag(infoReader.Read7BitEncodedInt()) + midLat; var maxLon = (int)EncodeHelpers.DecodeZigZag(infoReader.Read7BitEncodedInt()) + midLon; return(new WayInfo { Id = cid, MidLat = midLat, MidLon = midLon, Rect = new BoundingRect { MinLat = minLat, MinLon = minLon, MaxLat = maxLat, MaxLon = maxLon } }); } infoStream.Position += 8; infoReader.Skip7BitInt(); infoReader.Skip7BitInt(); infoReader.Skip7BitInt(); infoReader.Skip7BitInt(); } return(null); }
private void WriteWayInfo(SWay way) { infoWriter.Write7BitEncodedInt(way.Id); var rect = way.Rect; infoWriter.Write(rect.MinLat); infoWriter.Write(rect.MinLon); infoWriter.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(way.MidLat - rect.MinLat)); infoWriter.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(way.MidLon - rect.MinLon)); infoWriter.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(rect.MaxLat - way.MidLat)); infoWriter.Write7BitEncodedInt(EncodeHelpers.EncodeZigZag(rect.MaxLon - way.MidLon)); infoLength = infoStream.Position; }
public long ReadZigZag() { lastSigned += EncodeHelpers.DecodeZigZag(reader.Read7BitEncodedInt()); return(lastSigned); }