1 /** 2 * --------- 3 * |.##> <##.| Open Smart Card Development Platform (www.openscdp.org) 4 * |# #| 5 * |# #| Copyright (c) 1999-2008 CardContact Software & System Consulting 6 * |'##> <##'| Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de) 7 * --------- 8 * 9 * This file is part of OpenSCDP. 10 * 11 * OpenSCDP is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License version 2 as 13 * published by the Free Software Foundation. 14 * 15 * OpenSCDP is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with OpenSCDP; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 * @fileoverview Data model as reference data for tests 25 */ 26 27 28 29 /** 30 * Create data model object 31 * 32 * @class Class providing for a reference model containing static card data 33 * @constructor 34 */ 35 function CardDataModel() { 36 this.dm = { name: "CardSIM" }; 37 38 this.dm.MF = { fid:"3F00"}; 39 CardDataModel.populateFromProfile(this.dm.MF, CardDataModel.path + "/mf.xml"); 40 41 var k = new Key(); 42 k.setComponent(Key.AES, new ByteString("7CA110454A1A6E570131D9619DC1376E4A1A6E570131D961", HEX)); 43 this.dm.MF.K_MAC = k; 44 45 var k = new Key(); 46 k.setComponent(Key.AES, new ByteString("0131D9619DC1376E7CA110454A1A6E579DC1376E7CA11045", HEX)); 47 this.dm.MF.K_ENC = k; 48 49 50 } 51 52 CardDataModel.path = GPSystem.mapFilename("", GPSystem.CWD); 53 54 55 56 /** 57 * Populate a node from an XML profile 58 * 59 * @param {Object} node the node where the data from the profile is inserted 60 * @param {String} profile the XML application profile 61 */ 62 CardDataModel.populateFromProfile = function(node, profile) { 63 var xml = GPXML.parse(profile); 64 var list = xml.DataStructure.FileStructure.EF; 65 for (var i = 0; i < list.length; i++) { 66 var item = list[i]; 67 node[item.name] = item; 68 } 69 } 70 71 72 73 /** 74 * Return the node at the given path 75 * 76 * @param {String} path the path to the node 77 * @type Object 78 * @return the node 79 */ 80 CardDataModel.prototype.getNode = function(path) { 81 var items = path.split("/"); 82 var node = this.dm; 83 for (var i = 0; i <items.length; i++) { 84 node = node[items[i]]; 85 if (!node) { 86 throw new GPError("CardDataModel", GPError.OBJECT_NOT_FOUND, 0, "Element " + path + " not found in data model"); 87 } 88 // print(items[i] + ":" + node); 89 } 90 return node; 91 } 92 93 94 95 /** 96 * Dump the complete model 97 */ 98 CardDataModel.prototype.dump = function() { 99 function _dump(indent, o) { 100 for (i in o) { 101 var t = o[i]; 102 if (typeof(t) == "object") { 103 print(indent + i + ":"); 104 _dump(indent + " ", t); 105 } else { 106 print(indent + i + ": " + o[i]); 107 } 108 } 109 } 110 111 _dump("", this.dm); 112 } 113