public BitChatInfo(BinaryReader bR) { if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "BI") { throw new BitChatException("Invalid BitChatInfo data format."); } byte version = bR.ReadByte(); switch (version) { case 1: case 2: case 3: case 4: if (version > 2) { _type = (BitChatNetworkType)bR.ReadByte(); } else { _type = BitChatNetworkType.GroupChat; } _networkNameOrPeerEmailAddress = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())); _sharedSecret = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())); if (version > 3) { _networkID = new BinaryID(bR.ReadBytes(bR.ReadByte())); } _peerCerts = new Certificate[bR.ReadByte()]; for (int i = 0; i < _peerCerts.Length; i++) { _peerCerts[i] = new Certificate(bR); } _sharedFiles = new SharedFileInfo[bR.ReadByte()]; for (int i = 0; i < _sharedFiles.Length; i++) { _sharedFiles[i] = new SharedFileInfo(bR); } if (version > 1) { _trackerURIs = new Uri[bR.ReadByte()]; for (int i = 0; i < _trackerURIs.Length; i++) { _trackerURIs[i] = new Uri(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()))); } } break; default: throw new BitChatException("BitChatInfo data version not supported."); } }
public BitChatInfo(BinaryReader bR) { if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "BI") throw new BitChatException("Invalid BitChatInfo data format."); byte version = bR.ReadByte(); switch (version) { case 1: case 2: case 3: case 4: if (version > 2) _type = (BitChatNetworkType)bR.ReadByte(); else _type = BitChatNetworkType.GroupChat; _networkNameOrPeerEmailAddress = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())); _sharedSecret = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())); if (version > 3) { int networkIDLen = bR.ReadByte(); if (networkIDLen > 0) _networkID = new BinaryID(bR.ReadBytes(networkIDLen)); } _peerCerts = new Certificate[bR.ReadByte()]; for (int i = 0; i < _peerCerts.Length; i++) _peerCerts[i] = new Certificate(bR); _sharedFiles = new SharedFileInfo[bR.ReadByte()]; for (int i = 0; i < _sharedFiles.Length; i++) _sharedFiles[i] = new SharedFileInfo(bR); if (version > 1) { _trackerURIs = new Uri[bR.ReadByte()]; for (int i = 0; i < _trackerURIs.Length; i++) _trackerURIs[i] = new Uri(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()))); } break; default: throw new BitChatException("BitChatInfo data version not supported."); } }
public BitChatInfo(Stream s) { BincodingDecoder decoder = new BincodingDecoder(s, "BI"); while (true) { Bincoding value = decoder.DecodeNext(); if (value.Type == BincodingType.NULL) { break; } KeyValuePair <string, Bincoding> pair = value.GetKeyValuePair(); switch (pair.Key) { case "type": _type = (BitChatNetworkType)pair.Value.GetByteValue(); break; case "network_name": _networkNameOrPeerEmailAddress = pair.Value.GetStringValue(); break; case "shared_secret": _sharedSecret = pair.Value.GetStringValue(); break; case "enable_tracking": _enableTracking = pair.Value.GetBooleanValue(); break; case "send_invitation": _sendInvitation = pair.Value.GetBooleanValue(); break; case "invitation_sender": _invitationSender = pair.Value.GetStringValue(); break; case "invitation_message": _invitationMessage = pair.Value.GetStringValue(); break; case "network_status": _networkStatus = (BitChatNetworkStatus)pair.Value.GetByteValue(); break; case "hashed_peer_email_address": _hashedPeerEmailAddress = new BinaryNumber(pair.Value.Value); break; case "network_id": _networkID = new BinaryNumber(pair.Value.Value); break; case "network_secret": _networkSecret = new BinaryNumber(pair.Value.Value); break; case "message_store_id": _messageStoreID = pair.Value.GetStringValue(); break; case "message_store_key": _messageStoreKey = pair.Value.Value; break; case "group_image_date_modified": _groupImageDateModified = pair.Value.GetLongValue(); break; case "group_image": _groupImage = pair.Value.Value; break; case "mute": _mute = pair.Value.GetBooleanValue(); break; case "peer_certs": { List <Bincoding> peerCerts = pair.Value.GetList(); _peerCerts = new Certificate[peerCerts.Count]; int i = 0; foreach (Bincoding item in peerCerts) { _peerCerts[i++] = new Certificate(item.GetValueStream()); } } break; case "shared_files": { List <Bincoding> sharedFiles = pair.Value.GetList(); _sharedFiles = new SharedFileInfo[sharedFiles.Count]; int i = 0; foreach (Bincoding item in sharedFiles) { _sharedFiles[i++] = new SharedFileInfo(item.GetValueStream()); } } break; case "tracker_list": { List <Bincoding> trackerList = pair.Value.GetList(); _trackerURIs = new Uri[trackerList.Count]; int i = 0; foreach (Bincoding item in trackerList) { _trackerURIs[i++] = new Uri(item.GetStringValue()); } } break; } } }
public BitChatInfo(BitChatNetworkType type, string networkNameOrPeerEmailAddress, string sharedSecret, BinaryID networkID, Certificate[] peerCerts, SharedFileInfo[] sharedFiles, Uri[] trackerURIs) { _type = type; _networkNameOrPeerEmailAddress = networkNameOrPeerEmailAddress; _sharedSecret = sharedSecret; _networkID = networkID; _peerCerts = peerCerts; _sharedFiles = sharedFiles; _trackerURIs = trackerURIs; }