Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents KeyName Objects |
| 4 | */ |
| 5 | |
| 6 | var KeyName = function KeyName() { |
| 7 | |
| 8 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 9 | this.contentName = this.contentName;//contentName |
| 10 | this.publisherID =this.publisherID;//publisherID |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 11 | |
| 12 | }; |
| 13 | |
| 14 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 15 | KeyName.prototype.from_ccnb=function( decoder){ |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 16 | |
| 17 | |
| 18 | decoder.readStartElement(this.getElementLabel()); |
| 19 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 20 | this.contentName = new ContentName(); |
| 21 | this.contentName.from_ccnb(decoder); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 22 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 23 | if(LOG>4) console.log('KEY NAME FOUND: '); |
| 24 | |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 25 | if ( PublisherID.peek(decoder) ) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 26 | this.publisherID = new PublisherID(); |
| 27 | this.publisherID.from_ccnb(decoder); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | decoder.readEndElement(); |
| 31 | }; |
| 32 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 33 | KeyName.prototype.to_ccnb = function( encoder) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 34 | if (!this.validate()) { |
| 35 | throw new Exception("Cannot encode : field values missing."); |
| 36 | } |
| 37 | |
| 38 | encoder.writeStartElement(this.getElementLabel()); |
| 39 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 40 | this.contentName.to_ccnb(encoder); |
| 41 | if (null != this.publisherID) |
| 42 | this.publisherID.to_ccnb(encoder); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 43 | |
| 44 | encoder.writeEndElement(); |
| 45 | }; |
| 46 | |
| 47 | KeyName.prototype.getElementLabel = function() { return CCNProtocolDTags.KeyName; }; |
| 48 | |
| 49 | KeyName.prototype.validate = function() { |
| 50 | // DKS -- do we do recursive validation? |
| 51 | // null signedInfo ok |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 52 | return (null != this.contentName); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 53 | }; |