Example #1
0
        public virtual bool AuthenticateComponentsWithData(NSArray components, NSData authenticationData)
        {
            // Verify the authentication data against the components.  A good
            // authenticator would have a way of verifying the signature without
            // recomputing it.  We don't, in this example, so just recompute.
            NSData recomputedSignature = this.AuthenticationDataForComponents (components);

            // If the two NSDatas are not equal, authentication failure!
            if (!recomputedSignature.IsEqual (authenticationData)) {
                Console.WriteLine ("received signature {0} doesn't match computed signature {1}", authenticationData, recomputedSignature);
                return false;
            }
            return true;
        }
Example #2
0
        /// <summary>
        /// Create a <see cref="NSImage"/> from a stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>An autoreleased <see cref="NSImage"/> instance</returns>
        public static NSImage ImageFromStream(Stream stream)
        {
            NSImage result = null;
            if (stream != null)
            {
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length);

                NSData data = new NSData(buffer);
                result = new NSImage(data);
                data.Release();

                result.Autorelease();
            }
            return result;
        }
Example #3
0
		/// <summary>
		/// Returns a <see cref="NSData"/> instance from the serialization context.
		/// </summary>
		private static NSData DataFromSerialization (SerializationInfo info)
		{
			SerializationInfoEnumerator enumerator = info.GetEnumerator ();
			while (enumerator.MoveNext()) {
				if (String.Equals (enumerator.Name, "Data", StringComparison.OrdinalIgnoreCase)) {
					try {
						byte[] buffer = (byte[])enumerator.Value;
						if (buffer != null) {
							// Wraps the byte array into a NSdata
							NSData data = new NSData (buffer);
							return data.SafeAutorelease<NSData> ();
						}
					} catch (Exception) {
						// Do nothing
					}
				}
			}
			return null;
		}
Example #4
0
 /// <summary>
 /// Decrypts the given data by using the <see cref="ArtworkEncrypter"/> tool.
 /// </summary>
 /// <param name="encryptedData">The encrypted artwork data.</param>
 /// <param name="encryptionSeed">The encryption seed to use.</param>
 /// <returns>The decrypted artwork data.</returns>
 public static NSData DecryptData(NSData encryptedData, NSString encryptionSeed)
 {
     NSData result;
     try
     {
         Aes aes = FileEncrypter.GetProvider(encryptionSeed);
         byte[] encryptedBytes = encryptedData.GetBuffer();
         byte[] decryptedBytes = FileEncrypter.Decrypt(encryptedBytes, aes);
         result = new NSData(decryptedBytes);
     }
     catch (Exception e)
     {
         Logger.Warn("NSData", "Cannot decrypt encrypted data: " + e);
         result = NSData.Data.Copy<NSData>();
     }
     return result.SafeAutorelease<NSData>();
 }
Example #5
0
 /// <summary>
 /// Create a <see cref="NSData"/> from a stream.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <returns>A autoreleased <see cref="NSData"/> instance</returns>
 public static NSData DataFromStream(Stream stream)
 {
     NSData data = null;
     if (stream != null)
     {
         byte[] buffer = new byte[stream.Length];
         stream.Read(buffer, 0, (int)stream.Length);
         data = new NSData(buffer);
         data.Autorelease();
     }
     return data;
 }
Example #6
0
 public override bool LoadDataRepresentationOfType(NSData data, NSString aType)
 {
     // Insert code here to read your document from the given data.  You can also choose to override
     // -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
     return true;
 }
Example #7
0
 public bool readFromData(NSData data, NSString typeName, IntPtr outError)
 {
     // set the contents of this document by reading from data of a specified type
     this.Model = data;
     this.UpdateView();
     return true;
 }
Example #8
0
 /// <summary>
 /// Decrypts the given data and return an image.
 /// </summary>
 /// <param name="encryptedData">The encrypted artwork data.</param>
 /// <param name="encryptionSeed">The encryption seed to use.</param>
 /// <returns>The decrypted artwork image.</returns>
 public static NSImage ImageFromEncryptedData(NSData encryptedData, NSString encryptionSeed)
 {
     NSData decryptedData = NSData.DecryptData(encryptedData, encryptionSeed);
     NSImage image = new NSImage(decryptedData);
     return image.SafeAutorelease<NSImage>();
 }
Example #9
0
 public bool LoadDataRepresentation(NSData data, NSString aType)
 {
     return true;
 }
Example #10
0
			/// <summary>
			/// Converts the given object to the type of this converter, using the specified context and culture information.
			/// </summary>
			/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param>
			/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"/> to use as the current culture.</param>
			/// <param name="value">The <see cref="T:System.Object"/> to convert.</param>
			/// <returns>
			/// An <see cref="T:System.Object"/> that represents the converted value.
			/// </returns>
			/// <exception cref="T:System.NotSupportedException">
			/// The conversion cannot be performed.
			/// </exception>
			public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
			{
				// As pool are scoped, it does not hurt if we create ours during the method call.
				using (NSAutoreleasePool pool = new NSAutoreleasePool()) {
					byte[] rawData = value as byte[];
					if (rawData == null) {
						return base.ConvertFrom (context, culture, value);
					}

					// The image creation will be based on a NSData instance that wraps the byte array
					NSData data = new NSData (rawData);
					NSImage image = new NSImage (data);
					data.Release ();
					return image; // TODO: Find a way to avoid the memory leak as we do not release the instance...
				}
			}