1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Diagnostics; 7 using System.Threading; 8 9 using Internal.Cryptography; 10 11 namespace System.Security.Cryptography.Pkcs 12 { 13 public sealed class Pkcs9SigningTime : Pkcs9AttributeObject 14 { 15 // 16 // Constructors. 17 // 18 Pkcs9SigningTime()19 public Pkcs9SigningTime() 20 : this(DateTime.Now) 21 { 22 } 23 Pkcs9SigningTime(DateTime signingTime)24 public Pkcs9SigningTime(DateTime signingTime) 25 : base(Oids.SigningTime, Encode(signingTime)) 26 { 27 _lazySigningTime = signingTime; 28 } 29 Pkcs9SigningTime(byte[] encodedSigningTime)30 public Pkcs9SigningTime(byte[] encodedSigningTime) 31 : base(Oids.SigningTime, encodedSigningTime) 32 { 33 } 34 35 // 36 // Public properties. 37 // 38 39 public DateTime SigningTime 40 { 41 get 42 { 43 if (!_lazySigningTime.HasValue) 44 { 45 _lazySigningTime = Decode(RawData); 46 Interlocked.MemoryBarrier(); 47 } 48 return _lazySigningTime.Value; 49 } 50 } 51 CopyFrom(AsnEncodedData asnEncodedData)52 public override void CopyFrom(AsnEncodedData asnEncodedData) 53 { 54 base.CopyFrom(asnEncodedData); 55 _lazySigningTime = default(DateTime?); 56 } 57 58 // 59 // Private methods. 60 // 61 Decode(byte[] rawData)62 private static DateTime Decode(byte[] rawData) 63 { 64 if (rawData == null) 65 return default(DateTime); 66 67 return PkcsPal.Instance.DecodeUtcTime(rawData); 68 } 69 Encode(DateTime signingTime)70 private static byte[] Encode(DateTime signingTime) 71 { 72 return PkcsPal.Instance.EncodeUtcTime(signingTime); 73 } 74 75 private DateTime? _lazySigningTime = default(DateTime?); 76 } 77 } 78