blob: 3d3987a15fa56fcb00227f7e44d14984e5777bd1 [file] [log] [blame]
Meki Cherkaouib0365a72012-02-18 00:59:57 -08001
2var PublisherID = require('./PublisherID').PublisherID;
3var CCNProtocolDTags = require('./CCNProtocolDTags').CCNProtocolDTags;
4
5var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
6
7 if( typeof _pkd == "ByteArray") this.PublisherPublicKeyDigest = _pkd; // Byte Array
8 else if( typeof _pkd == "PublicKey") ;//TODO...
9
10};
11
12exports.PublisherPublicKeyDigest = PublisherPublicKeyDigest;
13
14
15PublisherPublicKeyDigest.prototype.decode = function( decoder) {
16
17 this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
18 if (null == this.PublisherPublicKeyDigest) {
19 throw new Exception("Cannot parse publisher key digest.");
20 }
21 if (this.PublisherPublicKeyDigest.length != PublisherID.PUBLISHER_ID_LEN) {
22
23 this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
24 }
25 };
26
27PublisherPublicKeyDigest.prototype.encode= function( encoder) {
28 if (!this.validate()) {
29 throw new Exception("Cannot encode : field values missing.");
30 }
31 this.encoder.writeElement(this.getElementLabel(), this.PublisherKeyDigest);
32};
33
34PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
35
36PublisherPublicKeyDigest.prototype.validate =function() {
37 return (null != this.PublisherKeyDigest);
38};