@@ -25,9 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
26
26
#endregion
27
27
28
- using System ;
29
- using System . Diagnostics ;
30
- using System . Linq ;
31
28
using System . Runtime . Serialization ;
32
29
using Newtonsoft . Json ;
33
30
using Newtonsoft . Json . Linq ;
@@ -154,7 +151,7 @@ public void OnDeserialized(StreamingContext ctx)
154
151
155
152
internal class DeleteRequest : RequestBase
156
153
{
157
- public DeleteRequest ( Node node )
154
+ public DeleteRequest ( INode node )
158
155
: base ( "d" )
159
156
{
160
157
this . Node = node . Id ;
@@ -171,7 +168,7 @@ public DeleteRequest(Node node)
171
168
172
169
internal class GetDownloadLinkRequest : RequestBase
173
170
{
174
- public GetDownloadLinkRequest ( Node node )
171
+ public GetDownloadLinkRequest ( INode node )
175
172
: base ( "l" )
176
173
{
177
174
this . Id = node . Id ;
@@ -188,7 +185,7 @@ public GetDownloadLinkRequest(Node node)
188
185
189
186
internal class CreateNodeRequest : RequestBase
190
187
{
191
- private CreateNodeRequest ( Node parentNode , NodeType type , string attributes , string key , string completionHandle )
188
+ private CreateNodeRequest ( INode parentNode , NodeType type , string attributes , string key , string completionHandle )
192
189
: base ( "p" )
193
190
{
194
191
this . ParentId = parentNode . Id ;
@@ -204,12 +201,12 @@ private CreateNodeRequest(Node parentNode, NodeType type, string attributes, str
204
201
} ;
205
202
}
206
203
207
- public static CreateNodeRequest CreateFileNodeRequest ( Node parentNode , string attributes , string key , string completionHandle )
204
+ public static CreateNodeRequest CreateFileNodeRequest ( INode parentNode , string attributes , string key , string completionHandle )
208
205
{
209
206
return new CreateNodeRequest ( parentNode , NodeType . File , attributes , key , completionHandle ) ;
210
207
}
211
208
212
- public static CreateNodeRequest CreateFolderNodeRequest ( Node parentNode , string attributes , string key )
209
+ public static CreateNodeRequest CreateFolderNodeRequest ( INode parentNode , string attributes , string key )
213
210
{
214
211
return new CreateNodeRequest ( parentNode , NodeType . Directory , attributes , key , "xxxxxxxx" ) ;
215
212
}
@@ -266,7 +263,7 @@ internal class UploadUrlResponse
266
263
267
264
internal class DownloadUrlRequest : RequestBase
268
265
{
269
- public DownloadUrlRequest ( Node node )
266
+ public DownloadUrlRequest ( INode node )
270
267
: base ( "g" )
271
268
{
272
269
this . Id = node . Id ;
@@ -311,7 +308,7 @@ internal class DownloadUrlResponse
311
308
312
309
internal class MoveRequest : RequestBase
313
310
{
314
- public MoveRequest ( Node node , Node destinationParentNode )
311
+ public MoveRequest ( INode node , INode destinationParentNode )
315
312
: base ( "m" )
316
313
{
317
314
this . Id = node . Id ;
@@ -341,133 +338,5 @@ public Attributes(string name)
341
338
public string Name { get ; set ; }
342
339
}
343
340
344
- #endregion
345
-
346
-
347
- #region Node
348
-
349
- [ DebuggerDisplay ( "Type: {Type} - Name: {Name} - Id: {Id}" ) ]
350
- public class Node : IEquatable < Node >
351
- {
352
- private static readonly DateTime OriginalDateTime = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , 0 ) ;
353
-
354
- #region Public properties
355
-
356
- [ JsonProperty ( "h" ) ]
357
- public string Id { get ; private set ; }
358
-
359
- [ JsonProperty ( "p" ) ]
360
- public string ParentId { get ; private set ; }
361
-
362
- [ JsonProperty ( "u" ) ]
363
- public string Owner { get ; private set ; }
364
-
365
- [ JsonProperty ( "t" ) ]
366
- public NodeType Type { get ; private set ; }
367
-
368
- [ JsonProperty ( "s" ) ]
369
- public long Size { get ; private set ; }
370
-
371
- [ JsonIgnore ]
372
- public string Name { get ; private set ; }
373
-
374
- [ JsonIgnore ]
375
- public DateTime LastModificationDate { get ; private set ; }
376
-
377
- [ JsonIgnore ]
378
- internal byte [ ] DecryptedKey { get ; private set ; }
379
-
380
- [ JsonIgnore ]
381
- internal byte [ ] Key { get ; private set ; }
382
-
383
- [ JsonIgnore ]
384
- internal byte [ ] Iv { get ; private set ; }
385
-
386
- [ JsonIgnore ]
387
- internal byte [ ] MetaMac { get ; private set ; }
388
-
389
- #endregion
390
-
391
- #region Deserialization
392
-
393
- [ JsonProperty ( "ts" ) ]
394
- private long SerializedLastModificationDate { get ; set ; }
395
-
396
- [ JsonProperty ( "a" ) ]
397
- private string SerializedAttributes { get ; set ; }
398
-
399
- [ JsonProperty ( "k" ) ]
400
- private string SerializedKey { get ; set ; }
401
-
402
- [ OnDeserialized ]
403
- public void OnDeserialized ( StreamingContext ctx )
404
- {
405
- byte [ ] masterKey = ( byte [ ] ) ( ( object [ ] ) ctx . Context ) [ 0 ] ;
406
- GetNodesResponse nodesResponse = ( GetNodesResponse ) ( ( object [ ] ) ctx . Context ) [ 1 ] ;
407
-
408
- this . LastModificationDate = OriginalDateTime . AddSeconds ( this . SerializedLastModificationDate ) . ToLocalTime ( ) ;
409
-
410
- if ( this . Type == NodeType . File || this . Type == NodeType . Directory )
411
- {
412
- int splitPosition = this . SerializedKey . IndexOf ( ":" , StringComparison . InvariantCulture ) ;
413
- byte [ ] encryptedKey = this . SerializedKey . Substring ( splitPosition + 1 ) . FromBase64 ( ) ;
414
-
415
- this . DecryptedKey = Crypto . DecryptKey ( encryptedKey , masterKey ) ;
416
- this . Key = this . DecryptedKey ;
417
-
418
- // If node is shared, we need to retrieve shared masterkey
419
- if ( nodesResponse . SharedKeys != null )
420
- {
421
- string owner = this . SerializedKey . Substring ( 0 , splitPosition ) ;
422
- GetNodesResponse . SharedKey sharedKey = nodesResponse . SharedKeys . FirstOrDefault ( x => x . Id == owner ) ;
423
- if ( sharedKey != null )
424
- {
425
- masterKey = Crypto . DecryptKey ( sharedKey . Key . FromBase64 ( ) , masterKey ) ;
426
-
427
- if ( this . Type == NodeType . Directory )
428
- {
429
- this . DecryptedKey = masterKey ;
430
- }
431
-
432
- this . Key = Crypto . DecryptKey ( encryptedKey , masterKey ) ;
433
- }
434
- }
435
-
436
- if ( this . Type == NodeType . File )
437
- {
438
- byte [ ] iv , metaMac , fileKey ;
439
- Crypto . GetPartsFromDecryptedKey ( this . DecryptedKey , out iv , out metaMac , out fileKey ) ;
440
-
441
- this . Iv = iv ;
442
- this . MetaMac = metaMac ;
443
- this . Key = fileKey ;
444
- }
445
-
446
- Attributes attributes = Crypto . DecryptAttributes ( this . SerializedAttributes . FromBase64 ( ) , this . Key ) ;
447
- this . Name = attributes . Name ;
448
- }
449
- }
450
-
451
- #endregion
452
-
453
- #region Equality
454
-
455
- public bool Equals ( Node other )
456
- {
457
- return other != null && this . Id == other . Id ;
458
- }
459
-
460
- #endregion
461
- }
462
-
463
- public enum NodeType
464
- {
465
- File = 0 ,
466
- Directory ,
467
- Root ,
468
- Inbox ,
469
- Trash
470
- }
471
-
472
- #endregion
341
+ #endregion\
473
342
}
0 commit comments