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">
|
Jeff Burke | 92dd8e4 | 2012-12-08 11:40:31 -0800 | [diff] [blame] | 4 | <!--
|
| 5 | See COPYING for copyright and distribution information.
|
| 6 | -->
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 7 | <html xmlns = "http://www.w3.org/1999/xhtml">
|
| 8 |
|
| 9 | <head>
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 10 | <title>NDN Encode/Decode Content Object</title>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 11 |
|
Jeff Thompson | 38422f4 | 2012-11-15 00:20:39 -0800 | [diff] [blame] | 12 | <script type="text/javascript" src="../Helper.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 13 |
|
| 14 | <script type="text/javascript">
|
| 15 |
|
| 16 | function encode(){
|
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 17 | var contentname = new Name( document.getElementById('contentname').value );
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 18 |
|
| 19 | var content = document.getElementById('content').value;
|
| 20 |
|
| 21 | var signedInfo = new SignedInfo();
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 22 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 23 | signedInfo.setFields();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 24 |
|
| 25 | //witness is null
|
| 26 | var signature = new Signature();
|
| 27 |
|
| 28 |
|
| 29 | var co = new ContentObject(contentname,signedInfo,content,signature);
|
| 30 |
|
| 31 | co.sign();
|
| 32 |
|
| 33 |
|
| 34 | var output = encodeToHexContentObject(co);
|
| 35 |
|
| 36 | document.getElementById('result').innerHTML = output;
|
| 37 |
|
| 38 | }
|
| 39 |
|
| 40 | function decode(){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 41 | var input = document.getElementById('result').innerHTML;
|
| 42 |
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 43 | input = input.toUpperCase();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 44 |
|
| 45 | var co = decodeHexContentObject(input);
|
| 46 |
|
| 47 | if(LOG>3)console.log('CONTENT OBJECT DECODED');
|
| 48 | if(LOG>3)console.log(co);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 49 |
|
jeff | cc8b3a9 | 2012-09-03 15:13:27 -0700 | [diff] [blame] | 50 | document.getElementById('result').innerHTML = contentObjectToHtml(co);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 51 | }
|
| 52 |
|
| 53 | </script>
|
| 54 |
|
| 55 | </head>
|
| 56 | <body >
|
| 57 | <form>
|
| 58 |
|
| 59 | Please Enter a Content Name:<br />
|
| 60 |
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 61 | <input id="contentname" type="text" name="CONTENTNAME" value="/ndn/abc" />
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 62 |
|
Jeff Thompson | 12b029d | 2012-08-26 11:51:27 -0700 | [diff] [blame] | 63 | <br />Please Enter the Content:<br />
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 64 |
|
| 65 | <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
|
| 66 |
|
| 67 | </form>
|
| 68 | <button onclick="encode()">Encode</button>
|
| 69 | <button onclick="decode()">Decode</button>
|
| 70 |
|
| 71 |
|
Jeff Thompson | 12b029d | 2012-08-26 11:51:27 -0700 | [diff] [blame] | 72 | <p id="result"></p>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 73 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 74 |
|
| 75 | </body>
|
jeff | cc8b3a9 | 2012-09-03 15:13:27 -0700 | [diff] [blame] | 76 | </html>
|