blob: e958c3f0771d5cc4e346f4647353a9e5a25025d6 [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents KeyName Objects
4 */
5
6var KeyName = function KeyName() {
7
8
Jeff Thompsone85ff1d2012-09-29 21:21:57 -07009 this.contentName = this.contentName;//contentName
10 this.publisherID =this.publisherID;//publisherID
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070011
12};
13
14
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070015KeyName.prototype.from_ccnb=function( decoder){
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070016
17
18 decoder.readStartElement(this.getElementLabel());
19
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070020 this.contentName = new ContentName();
21 this.contentName.from_ccnb(decoder);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070022
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070023 if(LOG>4) console.log('KEY NAME FOUND: ');
24
Meki Cherkaoui8f173612012-06-06 01:05:40 -070025 if ( PublisherID.peek(decoder) ) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070026 this.publisherID = new PublisherID();
27 this.publisherID.from_ccnb(decoder);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070028 }
29
30 decoder.readEndElement();
31};
32
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070033KeyName.prototype.to_ccnb = function( encoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070034 if (!this.validate()) {
35 throw new Exception("Cannot encode : field values missing.");
36 }
37
38 encoder.writeStartElement(this.getElementLabel());
39
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070040 this.contentName.to_ccnb(encoder);
41 if (null != this.publisherID)
42 this.publisherID.to_ccnb(encoder);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070043
44 encoder.writeEndElement();
45};
46
47KeyName.prototype.getElementLabel = function() { return CCNProtocolDTags.KeyName; };
48
49KeyName.prototype.validate = function() {
50 // DKS -- do we do recursive validation?
51 // null signedInfo ok
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070052 return (null != this.contentName);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070053};