blob: dd90aab740770c74dd778faeafbd1786d62d4361 [file] [log] [blame]
Meki Cherkaoui97e7a592012-04-14 02:50:06 -07001
2
3var PublisherType = function PublisherType(_tag){
4 this.KEY =(CCNProtocolDTags.PublisherPublicKeyDigest);
5 this.CERTIFICATE= (CCNProtocolDTags.PublisherCertificateDigest);
6 this.ISSUER_KEY= (CCNProtocolDTags.PublisherIssuerKeyDigest);
7 this.ISSUER_CERTIFICATE =(CCNProtocolDTags.PublisherIssuerCertificateDigest);
8
9 this.Tag = _tag;
10};
11PublisherType.prototype.isTypeTagVal = function(tagVal) {
12 if ((tagVal == CCNProtocolDTags.PublisherPublicKeyDigest) ||
13 (tagVal == CCNProtocolDTags.PublisherCertificateDigest) ||
14 (tagVal == CCNProtocolDTags.PublisherIssuerKeyDigest) ||
15 (tagVal == CCNProtocolDTags.PublisherIssuerCertificateDigest)) {
16 return true;
17 }
18 return false;
19};
20
21
22var PublisherID = function PublisherID() {
23
24 this.PUBLISHER_ID_DIGEST_ALGORITHM = "SHA-256";
25 this.PUBLISHER_ID_LEN = 256/8;
26
27
28 this.PublisherID = generatePublicKeyDigest(key);//ByteArray
29 //CryptoUtil.generateKeyID(PUBLISHER_ID_DIGEST_ALGORITHM, key);
30 this.PublisherType = isIssuer ? PublisherType.ISSUER_KEY : PublisherType.KEY;//publisher Type
31
32};
33
34
35PublisherID.prototype.decode = function(decoder) {
36
37 // We have a choice here of one of 4 binary element types.
38 var nextTag = decoder.peekStartElementAsLong();
39
40 if (null == nextTag) {
41 throw new Exception("Cannot parse publisher ID.");
42 }
43
44 this.PublisherType = new PublisherType(nextTag);
45
46 if (!this.PublisherType.isTypeTagVal(nextTag)) {
47 throw new Exception("Invalid publisher ID, got unexpected type: " + nextTag);
48 }
49 this.PublisherID = decoder.readBinaryElement(nextTag);
50 if (null == _publisherID) {
51 throw new ContentDecodingException("Cannot parse publisher ID of type : " + nextTag + ".");
52 }
53};
54
55PublisherID.prototype.encode = function(encoder) {
56 if (!this.validate()) {
57 throw new Exception("Cannot encode " + this.getClass().getName() + ": field values missing.");
58 }
59
60 encoder.writeElement(this.getElementLabel(), this.PublisherID);
61};
62
63PublisherID.prototype.getElementLabel = function() {
64 return this.PublisherType.Tag;
65};
66
67
68PublisherID.prototype.validate = function(){
69 return ((null != id() && (null != type())));
70};
71
72
73