blob: 6cae7f612db45cb9ccf85bc7b6362b6c5083adb5 [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents PublisherPublicKeyDigest Objects
4 */
5var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
6
Meki Cherkaoui8f173612012-06-06 01:05:40 -07007 //this.PUBLISHER_ID_LEN = 256/8;
8 this.PUBLISHER_ID_LEN = 512/8;
Meki Cherkaouif3d8f692012-05-18 15:44:28 -07009
Meki Cherkaoui8f173612012-06-06 01:05:40 -070010
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070011 this.publisherPublicKeyDigest = _pkd;
12 //if( typeof _pkd == "object") this.publisherPublicKeyDigest = _pkd; // Byte Array
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070013 //else if( typeof _pkd == "PublicKey") ;//TODO...
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070014
15};
16
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070017PublisherPublicKeyDigest.prototype.from_ccnb = function( decoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070018
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070019 this.publisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070020
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070021 if(LOG>4)console.log('Publisher public key digest is ' + this.publisherPublicKeyDigest);
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070022
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070023 if (null == this.publisherPublicKeyDigest) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070024 throw new Error("Cannot parse publisher key digest.");
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070025 }
26
27 //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason)
28
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070029 if (this.publisherPublicKeyDigest.length != this.PUBLISHER_ID_LEN) {
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070030
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070031 console.log('LENGTH OF PUBLISHER ID IS WRONG! Expected ' + this.PUBLISHER_ID_LEN + ", got " + this.publisherPublicKeyDigest.length);
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070032
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070033 //this.publisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070034
35 }
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070036 };
37
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070038PublisherPublicKeyDigest.prototype.to_ccnb= function( encoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070039 //TODO Check that the ByteArray for the key is present
Meki Cherkaoui8f173612012-06-06 01:05:40 -070040 if (!this.validate()) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070041 throw new Error("Cannot encode : field values missing.");
Meki Cherkaoui8f173612012-06-06 01:05:40 -070042 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070043 if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.publisherPublicKeyDigest);
44 encoder.writeElement(this.getElementLabel(), this.publisherPublicKeyDigest);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070045};
46
47PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
48
49PublisherPublicKeyDigest.prototype.validate =function() {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070050 return (null != this.publisherPublicKeyDigest);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070051};