gotthardp / gen_coap

Generic Erlang CoAP Client/Server
Other
106 stars 47 forks source link

Unexpected trouble with empty payload #3

Closed qingchuwudi closed 8 years ago

qingchuwudi commented 8 years ago

If payload is empty, it will give me an unexpected result which is not fllowed by 16#FF.

%% coap_message_parser.erl , line 163
encode_option_list(Options, <<>>) ->
    encode_option_list1(Options);
encode_option_list(Options, Payload) ->
    <<(encode_option_list1(Options))/bytes, 16#FF, Payload/bytes>>.

There is a problem. When encypt CoAP with AES , pads are necessary, But there is no tag to split them after decryption.

I think this is better:

%% coap_message_parser.erl, line 214
encode_option_list([], _LastNum, Acc) ->
    <<Acc/binary, 16#FF>>.
gotthardp commented 8 years ago

I believe the behavior is correct. The RFC 7252 says: The absence of the Payload Marker denotes a zero-length payload. Is the AES encryption you are applying described somewhere?

qingchuwudi commented 8 years ago

Yes, you are right. I'm using coap in our product with a little adjustment. And the options no longer the way it is.

gotthardp commented 8 years ago

If you can share some details I'd be interested to implement provisions for your extension into gen-coap, but it must not violate the standard and should be useful also to other people. For example, it could automatically add random padding.