blob: e418d574dee5d2a612963d1417d1611ee8d79a15 [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents Publisher and PublisherType Objects
4 */
5
6
7var PublisherType = function PublisherType(_tag){
8 this.KEY =(CCNProtocolDTags.PublisherPublicKeyDigest);
9 this.CERTIFICATE= (CCNProtocolDTags.PublisherCertificateDigest);
10 this.ISSUER_KEY= (CCNProtocolDTags.PublisherIssuerKeyDigest);
11 this.ISSUER_CERTIFICATE =(CCNProtocolDTags.PublisherIssuerCertificateDigest);
12
13 this.Tag = _tag;
14};
15
16var isTypeTagVal = function(tagVal) {
17 if ((tagVal == CCNProtocolDTags.PublisherPublicKeyDigest) ||
18 (tagVal == CCNProtocolDTags.PublisherCertificateDigest) ||
19 (tagVal == CCNProtocolDTags.PublisherIssuerKeyDigest) ||
20 (tagVal == CCNProtocolDTags.PublisherIssuerCertificateDigest)) {
21 return true;
22 }
23 return false;
24};
25
26
27
28
29var PublisherID = function PublisherID() {
30
31 this.PUBLISHER_ID_DIGEST_ALGORITHM = "SHA-256";
32 this.PUBLISHER_ID_LEN = 256/8;
33
34 //TODO, implement publisherID creation and key creation
35
36 //TODO implement generatePublicKeyDigest
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070037 this.publisherID =null;//= generatePublicKeyDigest(key);//ByteArray
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070038
39 //TODO implement generate key
40 //CryptoUtil.generateKeyID(PUBLISHER_ID_DIGEST_ALGORITHM, key);
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070041 this.publisherType = null;//isIssuer ? PublisherType.ISSUER_KEY : PublisherType.KEY;//publisher Type
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070042
43};
44
45
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070046PublisherID.prototype.from_ccnb = function(decoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070047
48 // We have a choice here of one of 4 binary element types.
49 var nextTag = decoder.peekStartElementAsLong();
50
51 if (null == nextTag) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070052 throw new Error("Cannot parse publisher ID.");
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070053 }
54
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070055 this.publisherType = new PublisherType(nextTag);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070056
57 if (!isTypeTagVal(nextTag)) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070058 throw new Error("Invalid publisher ID, got unexpected type: " + nextTag);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070059 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070060 this.publisherID = decoder.readBinaryElement(nextTag);
61 if (null == this.publisherID) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070062 throw new ContentDecodingException("Cannot parse publisher ID of type : " + nextTag + ".");
63 }
64};
65
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070066PublisherID.prototype.to_ccnb = function(encoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070067 if (!this.validate()) {
Jeff Thompson34a2ec02012-09-29 21:47:05 -070068 throw new Error("Cannot encode " + this.getClass().getName() + ": field values missing.");
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070069 }
70
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070071 encoder.writeElement(this.getElementLabel(), this.publisherID);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070072};
73
Jeff Thompson86aea882012-09-29 17:32:48 -070074PublisherID.peek = function(/* XMLDecoder */ decoder) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070075
76 //Long
77 nextTag = decoder.peekStartElementAsLong();
78
79 if (null == nextTag) {
80 // on end element
81 return false;
82 }
83 return (isTypeTagVal(nextTag));
84 };
85
86PublisherID.prototype.getElementLabel = function() {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070087 return this.publisherType.Tag;
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070088};
89
90PublisherID.prototype.validate = function(){
91 return ((null != id() && (null != type())));
92};
93
94
95