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