private byte[] GetAvatarHash(Stream stream) { var buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); return(ToxTools.Hash(buffer)); }
public void TestToxHash() { byte[] data = new byte[0xBEEF]; new Random().NextBytes(data); byte[] hash = ToxTools.Hash(data); }
public bool HashMatches(int friendNumber, byte[] hash) { byte[] avatar = GetAvatar(friendNumber); if (avatar == null) { return(false); } return(ToxTools.Hash(avatar).SequenceEqual(hash)); }
public void SendAvatar(int friendNumber, byte[] avatar) { //cancel any existing avatar file transfers with this friend first for (int i = _transfers.Count() - 1; i >= 0; i--) { //reverse loop to be able to delete entries while iterating through them, fun stuff var entry = _transfers.ElementAt(i); if (entry.Key.FriendNumber == friendNumber && entry.Key.Direction == FileTransferDirection.Outgoing) { CancelTransfer(entry.Key); } } var error = ToxErrorFileSend.Ok; ToxFileInfo fileInfo; if (avatar != null) { fileInfo = _tox.FileSend(friendNumber, ToxFileKind.Avatar, avatar.Length, "avatar.png", ToxTools.Hash(avatar), out error); } else { fileInfo = _tox.FileSend(friendNumber, ToxFileKind.Avatar, 0, "avatar.png"); } if (error != ToxErrorFileSend.Ok) { Debugging.Write("Could not send file transfer request: " + error.ToString()); return; } //no point in adding a 'dummy' transfer to our list if (avatar == null) { return; } var tr = new FileTransfer(fileInfo.Number, friendNumber, ToxFileKind.Avatar, FileTransferDirection.Outgoing); if (!_transfers.ContainsKey(tr)) { _transfers.Add(tr, new MemoryStream(avatar)); } else { Debugging.Write("Tried to add a filetransfer that's already in the list, panic!"); } }