SDWebImageDownloaderDecryptor.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDWebImageCompat.h"
  10. typedef NSData * _Nullable (^SDWebImageDownloaderDecryptorBlock)(NSData * _Nonnull data, NSURLResponse * _Nullable response);
  11. /**
  12. This is the protocol for downloader decryptor. Which decrypt the original encrypted data before decoding. Note progressive decoding is not compatible for decryptor.
  13. We can use a block to specify the downloader decryptor. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using `@convention(block)` to store a block into context options.
  14. */
  15. @protocol SDWebImageDownloaderDecryptor <NSObject>
  16. /// Decrypt the original download data and return a new data. You can use this to decrypt the data using your preferred algorithm.
  17. /// @param data The original download data
  18. /// @param response The URL response for data. If you modify the original URL response via response modifier, the modified version will be here. This arg is nullable.
  19. /// @note If nil is returned, the image download will be marked as failed with error `SDWebImageErrorBadImageData`
  20. - (nullable NSData *)decryptedDataWithData:(nonnull NSData *)data response:(nullable NSURLResponse *)response;
  21. @end
  22. /**
  23. A downloader response modifier class with block.
  24. */
  25. @interface SDWebImageDownloaderDecryptor : NSObject <SDWebImageDownloaderDecryptor>
  26. /// Create the data decryptor with block
  27. /// @param block A block to control decrypt logic
  28. - (nonnull instancetype)initWithBlock:(nonnull SDWebImageDownloaderDecryptorBlock)block;
  29. /// Create the data decryptor with block
  30. /// @param block A block to control decrypt logic
  31. + (nonnull instancetype)decryptorWithBlock:(nonnull SDWebImageDownloaderDecryptorBlock)block;
  32. @end
  33. /// Convenience way to create decryptor for common data encryption.
  34. @interface SDWebImageDownloaderDecryptor (Conveniences)
  35. /// Base64 Encoded image data decryptor
  36. @property (class, readonly, nonnull) SDWebImageDownloaderDecryptor *base64Decryptor;
  37. @end