-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize KeyFile to EncryptedFile (#17)
- Loading branch information
1 parent
a846e3c
commit a97c2c1
Showing
9 changed files
with
112 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace Zenon.Wallet.Json | ||
{ | ||
public class JEncryptedFile | ||
{ | ||
public static JEncryptedFile FromJObject(JObject json) | ||
{ | ||
var data = json.DeepClone() as JObject; | ||
var file = new JEncryptedFile(); | ||
file.crypto = data["crypto"] != null ? data["crypto"].ToObject<JCryptoData>() : null; | ||
data.Remove("crypto"); | ||
file.timestamp = data.Value<int>("timestamp"); | ||
data.Remove("timestamp"); | ||
file.version = data.Value<int>("version"); | ||
data.Remove("version"); | ||
file.metadata = data.Count != 0 ? data.ToObject<Dictionary<string, dynamic>>() : null; | ||
return file; | ||
} | ||
|
||
public static JObject ToJObject(JEncryptedFile file) | ||
{ | ||
var json = file.metadata != null ? JObject.FromObject(file.metadata) : new JObject(); | ||
if (file.crypto != null) | ||
{ | ||
json["crypto"] = JObject.FromObject(file.crypto); | ||
} | ||
json["timestamp"] = file.timestamp; | ||
json["version"] = file.version; | ||
return json; | ||
} | ||
|
||
public Dictionary<string, dynamic> metadata { get; set; } | ||
public JCryptoData crypto { get; set; } | ||
public int timestamp { get; set; } | ||
public int version { get; set; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Zenon.Wallet | ||
{ | ||
public class WalletException : Exception | ||
{ | ||
public WalletException(string message) | ||
: base(message) | ||
{ } | ||
} | ||
} |