Skip to content

Commit

Permalink
add some Foundation annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakey committed Sep 12, 2015
1 parent c7ee2dc commit 22ce76f
Show file tree
Hide file tree
Showing 63 changed files with 894 additions and 85 deletions.
5 changes: 5 additions & 0 deletions Categories/Foundation/NSData/NSData+APNSToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
#import <Foundation/Foundation.h>

@interface NSData (APNSToken)
/**
* @brief 将APNS NSData类型token 格式化成字符串
*
* @return 整理过后的字符串token
*/
- (NSString *)APNSToken;
@end
5 changes: 5 additions & 0 deletions Categories/Foundation/NSData/NSData+APNSToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#import "NSData+APNSToken.h"

@implementation NSData (APNSToken)
/**
* @brief 将APNS NSData类型token 格式化成字符串
*
* @return 字符串token
*/
- (NSString *)APNSToken {
return [[[[self description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
Expand Down
19 changes: 19 additions & 0 deletions Categories/Foundation/NSData/NSData+Base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,26 @@
#import <Foundation/Foundation.h>

@interface NSData (Base64)
/**
* @brief 字符串base64后转data
*
* @param string 传入字符串
*
* @return 传入字符串 base64后的data
*/
+ (NSData *)dataWithBase64EncodedString:(NSString *)string;
/**
* @brief NSData转string
*
* @param wrapWidth 换行长度 76 64
*
* @return base64后的字符串
*/
- (NSString *)base64EncodedStringWithWrapWidth:(NSUInteger)wrapWidth;
/**
* @brief NSData转string 换行长度默认64
*
* @return base64后的字符串
*/
- (NSString *)base64EncodedString;
@end
20 changes: 19 additions & 1 deletion Categories/Foundation/NSData/NSData+Base64.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
#import <Availability.h>

@implementation NSData (Base64)

/**
* @brief 字符串base64后转data
*
* @param string 传入字符串
*
* @return 传入字符串 base64后的data
*/
+ (NSData *)dataWithBase64EncodedString:(NSString *)string
{
if (![string length]) return nil;
Expand All @@ -28,6 +34,13 @@ + (NSData *)dataWithBase64EncodedString:(NSString *)string
}
return [decoded length]? decoded: nil;
}
/**
* @brief NSData转string
*
* @param wrapWidth 换行长度 76 64
*
* @return base64后的字符串
*/
- (NSString *)base64EncodedStringWithWrapWidth:(NSUInteger)wrapWidth
{
if (![self length]) return nil;
Expand Down Expand Up @@ -74,6 +87,11 @@ - (NSString *)base64EncodedStringWithWrapWidth:(NSUInteger)wrapWidth
}
return result;
}
/**
* @brief NSData转string 换行长度默认64
*
* @return base64后的字符串
*/
- (NSString *)base64EncodedString
{
return [self base64EncodedStringWithWrapWidth:0];
Expand Down
21 changes: 21 additions & 0 deletions Categories/Foundation/NSData/NSData+Encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
* @return data
*/
- (NSData *)encryptedWithAESUsingKey:(NSString*)key andIV:(NSData*)iv;
/**
* @brief 利用AES解密据
*
* @param key key
* @param iv iv
*
* @return 解密后数据
*/
- (NSData *)decryptedWithAESUsingKey:(NSString*)key andIV:(NSData*)iv;

/**
Expand All @@ -30,7 +38,20 @@
* @return data
*/
- (NSData *)encryptedWith3DESUsingKey:(NSString*)key andIV:(NSData*)iv;
/**
* @brief 利用3DES解密数据
*
* @param key key
* @param iv iv
*
* @return 解密后数据
*/
- (NSData *)decryptedWith3DESUsingKey:(NSString*)key andIV:(NSData*)iv;

/**
* @brief NSData 转成UTF8 字符串
*
* @return 转成UTF8 字符串
*/
- (NSString *)UTF8String;
@end
42 changes: 37 additions & 5 deletions Categories/Foundation/NSData/NSData+Encrypt.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
#import <CommonCrypto/CommonCryptor.h>

@implementation NSData (Encrypt)

/**
* 利用AES加密数据
*
* @param key key
* @param iv iv description
*
* @return data
*/
- (NSData*)encryptedWithAESUsingKey:(NSString*)key andIV:(NSData*)iv {

NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -38,7 +45,14 @@ - (NSData*)encryptedWithAESUsingKey:(NSString*)key andIV:(NSData*)iv {
return nil;

}

/**
* @brief 利用AES解密据
*
* @param key key
* @param iv iv
*
* @return 解密后数据
*/
- (NSData*)decryptedWithAESUsingKey:(NSString*)key andIV:(NSData*)iv {

NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -66,7 +80,14 @@ - (NSData*)decryptedWithAESUsingKey:(NSString*)key andIV:(NSData*)iv {
return nil;

}

/**
* 利用3DES加密数据
*
* @param key key
* @param iv iv description
*
* @return data
*/
- (NSData*)encryptedWith3DESUsingKey:(NSString*)key andIV:(NSData*)iv {

NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -94,7 +115,14 @@ - (NSData*)encryptedWith3DESUsingKey:(NSString*)key andIV:(NSData*)iv {
return nil;

}

/**
* @brief 利用3DES解密数据
*
* @param key key
* @param iv iv
*
* @return 解密后数据
*/
- (NSData*)decryptedWith3DESUsingKey:(NSString*)key andIV:(NSData*)iv {

NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -122,7 +150,11 @@ - (NSData*)decryptedWith3DESUsingKey:(NSString*)key andIV:(NSData*)iv {
return nil;

}

/**
* @brief NSData 转成UTF8 字符串
*
* @return 转成UTF8 字符串
*/
-(NSString *)UTF8String{
return [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding];
}
Expand Down
20 changes: 17 additions & 3 deletions Categories/Foundation/NSData/NSData+Gzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@
#import <Foundation/Foundation.h>
extern NSString* const GzipErrorDomain;
@interface NSData (Gzip)
/// GZIP压缩
/**
* @brief GZIP压缩
*
* @param level 压缩级别
*
* @return 压缩后的数据
*/
- (NSData *)gzippedDataWithCompressionLevel:(float)level;

/// GZIP压缩
/**
* @brief GZIP压缩 压缩级别 默认-1
*
* @return 压缩后的数据
*/
- (NSData *)gzippedData;

/// GZIP解压
/**
* @brief GZIP解压
*
* @return 解压后数据
*/
- (NSData *)gunzippedData;
@end
15 changes: 10 additions & 5 deletions Categories/Foundation/NSData/NSData+Gzip.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#import <zlib.h>
@implementation NSData (Gzip)
#define SCFW_CHUNK_SIZE 16384

/**
* @brief GZIP压缩
* @brief GZIP压缩
*
* @param level 压缩级别
*
* @param level 压缩等级
* @return 压缩后的数据
*/
- (NSData *)gzippedDataWithCompressionLevel:(float)level
{
Expand Down Expand Up @@ -52,15 +53,19 @@ - (NSData *)gzippedDataWithCompressionLevel:(float)level
}

/**
* @brief GZIP压缩, 压缩等级默认-1
* @brief GZIP压缩 压缩级别
*
* @return 压缩后的数据
*/
- (NSData *)gzippedData
{
return [self gzippedDataWithCompressionLevel:-1.0f];
}

/**
* @brief GZIP解压
* @brief GZIP解压
*
* @return 解压后数据
*/
- (NSData *)gunzippedData
{
Expand Down
40 changes: 40 additions & 0 deletions Categories/Foundation/NSData/NSData+Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,53 @@
#import <Foundation/Foundation.h>

@interface NSData (Hash)
/**
* @brief md5 NSData
*/
@property (readonly) NSData *md5Data;
/**
* @brief sha1Data NSData
*/
@property (readonly) NSData *sha1Data;
/**
* @brief sha256Data NSData
*/
@property (readonly) NSData *sha256Data;
/**
* @brief sha512Data NSData
*/
@property (readonly) NSData *sha512Data;

/**
* @brief md5 NSData
*
* @param key 密钥
*
* @return 结果
*/
- (NSData *)hmacMD5DataWithKey:(NSData *)key;
/**
* @brief sha1Data NSData
*
* @param key 密钥
*
* @return 结果
*/
- (NSData *)hmacSHA1DataWithKey:(NSData *)key;
/**
* @brief sha256Data NSData
*
* @param key 密钥
*
* @return 结果
*/
- (NSData *)hmacSHA256DataWithKey:(NSData *)key;
/**
* @brief sha512Data NSData
*
* @param key 密钥
*
* @return 结果
*/
- (NSData *)hmacSHA512DataWithKey:(NSData *)key;
@end
Loading

0 comments on commit 22ce76f

Please sign in to comment.