From 0778dad12d9b78fb458e68b284a0e2279bb67326 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Tue, 13 Feb 2007 00:12:29 +0000 Subject: [PATCH] Bug 243906. Base64 encode binary values when persisting them. --- CASA/micasad/cache/Secret.cs | 15 ++++++++++++--- CASA/micasad/lss/LocalStorage.cs | 23 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/CASA/micasad/cache/Secret.cs b/CASA/micasad/cache/Secret.cs index 9ab66451..5b7040a5 100644 --- a/CASA/micasad/cache/Secret.cs +++ b/CASA/micasad/cache/Secret.cs @@ -219,9 +219,14 @@ namespace sscs.cache { this.ModifiedTime = DateTime.Now; } + } + + public void SetKeyValue(string key, byte[] baValue) + { + SetKeyValue(key, baValue, true); } - public void SetKeyValue(string key, byte[] baValue) + public void SetKeyValue(string key, byte[] baValue, bool bUpdateModifiedTime) { KeyValue kv; if (htKeyValues.Contains(key)) @@ -233,8 +238,12 @@ namespace sscs.cache { kv = new KeyValue(key, baValue); htKeyValues.Add(key, kv); - } - this.ModifiedTime = DateTime.Now; + } + + if (bUpdateModifiedTime) + { + this.ModifiedTime = DateTime.Now; + } } public KeyValue GetKeyValue(string key) diff --git a/CASA/micasad/lss/LocalStorage.cs b/CASA/micasad/lss/LocalStorage.cs index 326614d1..1e845b11 100644 --- a/CASA/micasad/lss/LocalStorage.cs +++ b/CASA/micasad/lss/LocalStorage.cs @@ -502,15 +502,21 @@ namespace sscs.lss xpath = "descendant::" + XmlConsts.keyValueNode; XmlNode keyValNode = keyNode.SelectSingleNode(xpath); - string keyValue = keyValNode.InnerText; - secret.SetKeyValue(key, keyValue, false); + string keyValue = keyValNode.InnerText; // set binary type if set if ((sIsBinary != null) && (sIsBinary.Equals("true"))) - { + { + byte[] baDec = Convert.FromBase64String(keyValue); + secret.SetKeyValue(key, baDec, false); + KeyValue kv = secret.GetKeyValue(key); kv.SetValueType(KeyValue.VALUE_TYPE_BINARY); } + else + { + secret.SetKeyValue(key, keyValue, false); + } // get time attributes on this key/value XmlNode timeNodeKey = keyNode.SelectSingleNode("descendant::" + XmlConsts.timeNode); @@ -799,7 +805,16 @@ namespace sscs.lss writer.WriteStartElement(XmlConsts.keyValueNode); if (bSaveValues) - writer.WriteString(value); + { + if (kv.GetValueType() == KeyValue.VALUE_TYPE_BINARY) + { + writer.WriteString(Convert.ToBase64String(kv.GetValueAsBytes())); + } + else + { + writer.WriteString(value); + } + } else writer.WriteString("");