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