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 | |
| 9 | this.ContentName = this.ContentName;//ContentName |
| 10 | this.PublisherID =this.PublisherID;//PublisherID |
| 11 | |
| 12 | }; |
| 13 | |
| 14 | |
| 15 | KeyName.prototype.decode=function( decoder){ |
| 16 | |
| 17 | |
| 18 | decoder.readStartElement(this.getElementLabel()); |
| 19 | |
| 20 | this.ContentName = new ContentName(); |
| 21 | this.ContentName.decode(decoder); |
| 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 | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 25 | if ( peek(decoder) ) { |
| 26 | this.PublisherID = new PublisherID(); |
| 27 | this.PublisherID.decode(decoder); |
| 28 | } |
| 29 | |
| 30 | decoder.readEndElement(); |
| 31 | }; |
| 32 | |
| 33 | KeyName.prototype.encode = function( encoder) { |
| 34 | if (!this.validate()) { |
| 35 | throw new Exception("Cannot encode : field values missing."); |
| 36 | } |
| 37 | |
| 38 | encoder.writeStartElement(this.getElementLabel()); |
| 39 | |
| 40 | this.ContentName.encode(encoder); |
| 41 | if (null != this.PublisherID) |
| 42 | this.PublisherID.encode(encoder); |
| 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 |
| 52 | return (null != this.ContentName); |
| 53 | }; |