Dear community, I'm just coding a little diameter avp converion and I need to pad the AVP string. According to RFC 3588, AVP string
that do not align on a 32-bit boundary MUST have the necessary padding 00.
examples (space between values is only to shown better and should be removed on final string):
e4 99 68 f8 41 ==> e4 99 68 f8 41 00 00 00
40 ==> 40 00 00 00
2a 2e ==> 2a 2e 00 00
My simple code just takes a string and convert it in hex, but I need to add 00 padding on the right basing on above rules/example:
$Origin_Host_CER="example.me";
$Origin_Host_CER =~ s/(.)/sprintf '%02x', ord $1/seg;
print "STX2HEX: $Origin_Host_CER\n\n";
print length($Origin_Host_CER)/2;
This will result in:
STX2HEX: 6578616d706c652e6d65
10
So, final string should have 2 padding:
6578616d706c652e6d650000
Could someone help me to understand how to do that possibility without use any external module?
Thank you
Lucas
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.