Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 3 | "DTD/xhtml1-strict.dtd">
|
| 4 | <html xmlns = "http://www.w3.org/1999/xhtml">
|
| 5 |
|
| 6 | <head>
|
Jeff Thompson | d9784e0 | 2012-10-18 23:39:39 -0700 | [diff] [blame] | 7 | <title>NDN Encode/Decode Interest</title>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 8 |
|
Jeff Thompson | 38422f4 | 2012-11-15 00:20:39 -0800 | [diff] [blame] | 9 | <script type="text/javascript" src="../Helper.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 10 |
|
| 11 | <script type="text/javascript">
|
| 12 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 13 | function encode() {
|
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 14 | var interest = new Interest( new Name(document.getElementById('interest').value ) );
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 15 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 16 | interest.minSuffixComponents = 2;
|
| 17 | interest.maxSuffixComponents = 4;
|
| 18 | interest.childSelector = 1;
|
| 19 | interest.answerOriginKind = 4;
|
| 20 | interest.scope = 2;
|
| 21 | interest.interestLifetime = 30;
|
| 22 | interest.nonce = new Uint8Array([0x61, 0x62, 0x61, 0x62, 0x61, 0x62]);
|
| 23 | var pkd = [];
|
| 24 | for (i = 0; i < 32; ++i)
|
| 25 | pkd.push(i);
|
| 26 | interest.publisherPublicKeyDigest = new PublisherPublicKeyDigest(new Uint8Array(pkd));
|
| 27 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 28 | var output = encodeToHexInterest(interest);
|
| 29 |
|
| 30 | document.getElementById('result').innerHTML = output;
|
| 31 |
|
| 32 | }
|
| 33 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 34 | function decode() {
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 35 | var input = document.getElementById('result').innerHTML;
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 36 |
|
| 37 | var interest = decodeHexInterest(input);
|
| 38 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 39 | if (LOG>3)console.log('INTEREST DECODED');
|
| 40 | if (LOG>3)console.log(interest);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 41 |
|
| 42 | ///////////////////////////////////////
|
| 43 |
|
| 44 | var output ="";
|
| 45 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 46 | if (interest.name != null && interest.name.components != null) {
|
| 47 | output += "Name: ";
|
| 48 | output += interest.name.getName();
|
| 49 | output += "<br/>";
|
| 50 | }
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 51 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 52 | if (interest.minSuffixComponents != null ) {
|
| 53 | output += "MinSuffixComponents : ";
|
| 54 | output += interest.minSuffixComponents;
|
| 55 | output += "<br/>";
|
| 56 | }
|
| 57 |
|
| 58 | if (interest.maxSuffixComponents != null ) {
|
| 59 | output += "MaxSuffixComponents : ";
|
| 60 | output += interest.maxSuffixComponents;
|
| 61 | output += "<br/>";
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 62 | }
|
| 63 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 64 | if (interest.publisherPublicKeyDigest != null ) {
|
| 65 | output += "PublisherPublicKeyDigest: ";
|
| 66 | output += DataUtils.toHex(interest.publisherPublicKeyDigest.publisherPublicKeyDigest);
|
| 67 | output += "<br/>";
|
| 68 | }
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 69 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 70 | if (interest.childSelector != null ) {
|
| 71 | output += "ChildSelector: ";
|
| 72 | output += interest.childSelector;
|
| 73 | output += "<br/>";
|
| 74 | }
|
| 75 |
|
| 76 | if (interest.answerOriginKind != null ) {
|
| 77 | output += "AnswerOriginKind: ";
|
| 78 | output += interest.answerOriginKind;
|
| 79 | output += "<br/>";
|
| 80 | }
|
| 81 |
|
| 82 | if (interest.scope != null ) {
|
| 83 | output += "Scope: ";
|
| 84 | output += interest.scope;
|
| 85 | output += "<br/>";
|
| 86 | }
|
| 87 |
|
| 88 | if (interest.interestLifetime != null ) {
|
| 89 | output += "InterestLifetime: ";
|
| 90 | output += interest.interestLifetime;
|
| 91 | output += "<br/>";
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 92 | }
|
| 93 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 94 | if (interest.nonce != null ) {
|
| 95 | output += "Nonce: ";
|
| 96 | output += DataUtils.toHex(interest.nonce);
|
| 97 | output += "<br/>";
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 98 | }
|
| 99 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 100 | document.getElementById('result').innerHTML = output;
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 101 | }
|
| 102 |
|
| 103 | </script>
|
| 104 |
|
| 105 | </head>
|
| 106 | <body >
|
| 107 | <form>
|
| 108 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 109 | Please Enter an Interest:<br />
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 110 |
|
jeff | 9797d3d | 2012-09-03 15:07:13 -0700 | [diff] [blame] | 111 | <input id="interest" type="text" name="INTEREST" value="/PARC/abc" />
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 112 |
|
| 113 | </form>
|
| 114 | <button onclick="encode()">Encode</button>
|
| 115 | <button onclick="decode()">Decode</button>
|
| 116 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 117 | <p id="result"></p>
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 118 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 119 |
|
| 120 |
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 121 | <!-- p id="result">01d2f2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b4559000002d28e310000</p-->
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 122 |
|
| 123 | </body>
|
jeff | 9797d3d | 2012-09-03 15:07:13 -0700 | [diff] [blame] | 124 | </html>
|