Comments (15)
I implement ZAP for curve.
YEAH!
Well this is adding a \0
character, because the C++ application does expect it...!
I do think there should be, something which encodes/decodes to a string (non-null terminated for C# applications), and something which encodes/decodes into a string (null terminated for C++ applications)...
from clrzmq4.
Hmm I have played arround a bit and found the following:
When I use a string (key), decode it to a byte array, encode it and get the string representation of it, the result is different from the original key, see the following example:
string orginalKey = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7";
byte[] decodedKey = orginalKey.ToZ85DecodedBytes(); // array size is 32 bytes, so it's fine
byte[] encoded = decodedKey.ToZ85Encoded(); // array is 41 bytes, there is a 0 at the end
string copyKey = Encoding.ASCII.GetString(encoded);
Debug.Assert(copyKey == orginalKey); // strings are not equal because of the \0 at the end
The bug happend in Z85.cs where in the Encode
method +1 is added to the destLen. The following change fixed the issue for me:
- int destLen = (Int32)(decoded.Length * 1.25) + 1;
+ int destLen = (Int32)(decoded.Length * 1.25);
Because the change is only on C# side in encoding, I don't think there is any impact to C++.
from clrzmq4.
You are on the right way... Do you want to implement a class Platform.iOS
?
from clrzmq4.
You made a PR with
using (var publicKeyData = DispoIntPtr.Alloc(destLen + 1))
using (var secretKeyData = DispoIntPtr.Alloc(destLen + 1))
Should we not also use just destLen
here? I'm asking, because I don't have test cases for Z85
.
from clrzmq4.
No, the +1 is because of the null termination of the C++ string which is not needed in C#. I just add it to ensure the buffer to be big enough.
If you whould add it whould happend to a C# string with \0 in it... which would be false...
from clrzmq4.
I suppose this is done in DispoIntPtr.Ansi.AllocStringNative
, when doing Marshal.StringToHGlobalAnsi(str)
. I did that too in that function, when you look down the comment, there I'm adding the 0x00
...
from clrzmq4.
AH, the method is never called in Z85.CurveKeypair
... So yes you likely need that +1
... :)
from clrzmq4.
This direct points me to something... I implemented the method to return byte[]
but I'm not sure this is correct. I did to be consistent because Encode also returns a byte[]
. But when I check the zmq documenatation, zmq_encode
is returning a char*
and this would be a string
in C#... think this would also affect some of the extension methods in Z85.ch
from clrzmq4.
Well you're right by returning byte[]
, because a C char
is a C# byte
... So that's fine.
I need to remove those Z85.~String
methods, they are just confusing...
from clrzmq4.
From zmq docu:
char *zmq_z85_encode (char *dest, const uint8_t *data, size_t size);
uint8_t* -> byte[]
char * -> string
Don't you agree?
from clrzmq4.
No, it is that a C char
is a C# byte
.
There may also be a definition for uint8_t
, which is also a C# byte
.
There maybe also a definition for uint16_t
, which is a C# UInt16
; which then allows to cast to C# char
... But you won't do that. Use instead Encoding.UTF8.GetString(bytes)
from a C char*
or a C# byte[]
, to get your C# string
out of those bytes.
from clrzmq4.
C char
has a range of -128..127, C# byte
has a range from 0..255, C# sbyte
is from -128..127 and is more like a unsigned char
or uint8_t
in C - but this is not the point here and I really don't want to tell you anything about C
I just think C signature char *zmq_z85_encode (char *dest, const uint8_t *data, size_t size);
indicates that the function takes a (C#) byte[] as input and returns a (C#) string... but don't care, I can really live with this.
from clrzmq4.
No, C# char[]
and C# string
don't have anything to do with C char
and C char*
.
You may just believe me for now, but once you need it, you will read this message again :)
from clrzmq4.
No, C# char doesn't have anything to do with C char.
I never claimed this. I claimed the C# byte
is more like a C unsigned char
or uint8_t
. But as I wrote, i don't care and will stop here because it dosn't matter.
from clrzmq4.
hehe
from clrzmq4.
Related Issues (20)
- News on ZeroMQ/clrzmq4 - New Initial Release HOT 4
- NuGet v4.1.0.28 does not include i386 and amd64 libs HOT 10
- latest v4.1.0.30 not include libsodium.dll while create instance HOT 1
- How do you see the times for request/reply messages processed?
- Fails to create ZContext under .net Core 3.0 HOT 7
- Heartbeat incompatibility with jeromq using curve
- Shared library issues with DotNet Core 2.1 under Linux HOT 1
- Nuget package with version that supports netstandard2.0 HOT 4
- Cannot get Ironhouse ZGuideExample to work
- Crash in ZSocket.SendMessage()
- Windows KERNELBASE exception and growing delay HOT 1
- Subscriptions not delivered to late publisher
- Missing Server/Client sockets HOT 1
- Non-conformant nuget package folder layout
- Please, make release with libzmq v4.3.4 included HOT 2
- Better signature to send string from ROUTER to DEALER
- NullReferenceException from ZeroMQ.ZPollItems.PollIn in ROUTER<-->DEALER communication
- Bug in public virtual bool Send(IEnumerable<ZFrame> frames, ZSocketFlags flags, out ZError error) HOT 2
- Correct handling of timeout during polling
- Receive event when a subscriber is connected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clrzmq4.