Browse files

Working with pin code

  • Loading branch information...
1 parent d232c0b commit ac9c63aa89a32aa2c8ae1000d1b2231941457f1a @macbury committed Feb 9, 2010
Showing with 13,532 additions and 0 deletions.
  1. +17 −0 Crypto/.svn/all-wcprops
  2. +96 −0 Crypto/.svn/entries
  3. +230 −0 Crypto/.svn/text-base/Base64Transcoder.c.svn-base
  4. +36 −0 Crypto/.svn/text-base/Base64Transcoder.h.svn-base
  5. +230 −0 Crypto/Base64Transcoder.c
  6. +36 −0 Crypto/Base64Transcoder.h
  7. +11 −0 English.lproj/.svn/all-wcprops
  8. +62 −0 English.lproj/.svn/entries
  9. +5 −0 English.lproj/.svn/prop-base/InfoPlist.strings.svn-base
  10. BIN English.lproj/.svn/text-base/InfoPlist.strings.svn-base
  11. BIN English.lproj/InfoPlist.strings
  12. +26 −0 Info.plist
  13. +35 −0 NSMutableURLRequest+Parameters.h
  14. +92 −0 NSMutableURLRequest+Parameters.m
  15. +53 −0 NSMutableURLRequest+ParametersTest.h
  16. +185 −0 NSMutableURLRequest+ParametersTest.m
  17. +34 −0 NSString+URLEncoding.h
  18. +52 −0 NSString+URLEncoding.m
  19. +33 −0 NSString+URLEncodingTest.h
  20. +38 −0 NSString+URLEncodingTest.m
  21. +34 −0 NSURL+Base.h
  22. +38 −0 NSURL+Base.m
  23. +35 −0 NSURL+BaseTest.h
  24. +39 −0 NSURL+BaseTest.m
  25. +45 −0 OAAsynchronousDataFetcher.h
  26. +134 −0 OAAsynchronousDataFetcher.m
  27. +40 −0 OAConsumer.h
  28. +51 −0 OAConsumer.m
  29. +35 −0 OAConsumerTest.h
  30. +38 −0 OAConsumerTest.m
  31. +45 −0 OADataFetcher.h
  32. +65 −0 OADataFetcher.m
  33. +38 −0 OADataFetcherTest.h
  34. +78 −0 OADataFetcherTest.m
  35. +32 −0 OAHMAC_SHA1SignatureProvider.h
  36. +58 −0 OAHMAC_SHA1SignatureProvider.m
  37. +34 −0 OAHMAC_SHA1SignatureProviderTest.h
  38. +42 −0 OAHMAC_SHA1SignatureProviderTest.m
  39. +68 −0 OAMutableURLRequest.h
  40. +235 −0 OAMutableURLRequest.m
  41. +49 −0 OAMutableURLRequestTest.h
  42. +111 −0 OAMutableURLRequestTest.m
  43. +31 −0 OAPlaintextSignatureProvider.h
  44. +43 −0 OAPlaintextSignatureProvider.m
  45. +34 −0 OAPlaintextSignatureProviderTest.h
  46. +37 −0 OAPlaintextSignatureProviderTest.m
  47. +45 −0 OARequestParameter.h
  48. +70 −0 OARequestParameter.m
  49. +39 −0 OARequestParameterTest.h
  50. +52 −0 OARequestParameterTest.m
  51. +43 −0 OAServiceTicket.h
  52. +51 −0 OAServiceTicket.m
  53. +34 −0 OASignatureProviding.h
  54. +37 −0 OATestServer.rb
  55. +44 −0 OAToken.h
  56. +107 −0 OAToken.m
  57. +46 −0 OATokenTest.h
  58. +95 −0 OATokenTest.m
  59. +19 −0 OAToken_KeychainExtensions.h
  60. +94 −0 OAToken_KeychainExtensions.m
  61. +39 −0 OAuthConsumer.h
  62. +23 −0 OAuthConsumer.xcodeproj/.svn/all-wcprops
  63. +130 −0 OAuthConsumer.xcodeproj/.svn/entries
  64. +1,528 −0 OAuthConsumer.xcodeproj/.svn/text-base/jon.mode1v3.svn-base
  65. +1,712 −0 OAuthConsumer.xcodeproj/.svn/text-base/jon.pbxuser.svn-base
  66. +747 −0 OAuthConsumer.xcodeproj/.svn/text-base/project.pbxproj.svn-base
  67. +1,377 −0 OAuthConsumer.xcodeproj/MacBury.mode1v3
  68. +426 −0 OAuthConsumer.xcodeproj/MacBury.pbxuser
  69. +1,528 −0 OAuthConsumer.xcodeproj/jon.mode1v3
  70. +1,712 −0 OAuthConsumer.xcodeproj/jon.pbxuser
  71. +747 −0 OAuthConsumer.xcodeproj/project.pbxproj
  72. +20 −0 OAuthConsumerTestSuite-Info.plist
  73. +7 −0 OAuthConsumer_Prefix.pch
View
17 Crypto/.svn/all-wcprops
@@ -0,0 +1,17 @@
+K 25
+svn:wc:ra_dav:version-url
+V 50
+/svn/!svn/ver/1164/code/obj-c/OAuthConsumer/Crypto
+END
+Base64Transcoder.h
+K 25
+svn:wc:ra_dav:version-url
+V 68
+/svn/!svn/ver/510/code/obj-c/OAuthConsumer/Crypto/Base64Transcoder.h
+END
+Base64Transcoder.c
+K 25
+svn:wc:ra_dav:version-url
+V 68
+/svn/!svn/ver/510/code/obj-c/OAuthConsumer/Crypto/Base64Transcoder.c
+END
View
96 Crypto/.svn/entries
@@ -0,0 +1,96 @@
+10
+
+dir
+1168
+http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/Crypto
+http://oauth.googlecode.com/svn
+
+
+
+2010-01-30T17:16:02.932304Z
+1164
+dougie.richardson
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+f7ae4463-c52f-0410-a7dc-93bad6e629e8
+
+Base64Transcoder.h
+file
+
+
+
+
+2010-02-09T14:46:10.000000Z
+2180848d29c77748438f71065c0206bb
+2008-04-09T02:00:08.966440Z
+510
+jwight
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1673
+
+Base64Transcoder.c
+file
+
+
+
+
+2010-02-09T14:46:10.000000Z
+ac95de79f8e4dc74dc8447f9ff7ee0cc
+2008-04-09T02:00:08.966440Z
+510
+jwight
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+9290
+
View
230 Crypto/.svn/text-base/Base64Transcoder.c.svn-base
@@ -0,0 +1,230 @@
+/*
+ * Base64Transcoder.c
+ * Base64Test
+ *
+ * Created by Jonathan Wight on Tue Mar 18 2003.
+ * Copyright (c) 2003 Toxic Software. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Base64Transcoder.h"
+
+#include <math.h>
+#include <string.h>
+
+const u_int8_t kBase64EncodeTable[64] = {
+ /* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D',
+ /* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H',
+ /* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L',
+ /* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P',
+ /* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T',
+ /* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X',
+ /* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b',
+ /* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f',
+ /* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j',
+ /* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n',
+ /* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r',
+ /* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v',
+ /* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z',
+ /* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3',
+ /* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7',
+ /* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/'
+};
+
+/*
+-1 = Base64 end of data marker.
+-2 = White space (tabs, cr, lf, space)
+-3 = Noise (all non whitespace, non-base64 characters)
+-4 = Dangerous noise
+-5 = Illegal noise (null byte)
+*/
+
+const int8_t kBase64DecodeTable[128] = {
+ /* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3,
+ /* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3,
+ /* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2,
+ /* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3,
+ /* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3,
+ /* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3,
+ /* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3,
+ /* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3,
+ /* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3,
+ /* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3,
+ /* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62,
+ /* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63,
+ /* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55,
+ /* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59,
+ /* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3,
+ /* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3,
+ /* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2,
+ /* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6,
+ /* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10,
+ /* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14,
+ /* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18,
+ /* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22,
+ /* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3,
+ /* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3,
+ /* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28,
+ /* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32,
+ /* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36,
+ /* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40,
+ /* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44,
+ /* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48,
+ /* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3,
+ /* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3
+};
+
+const u_int8_t kBits_00000011 = 0x03;
+const u_int8_t kBits_00001111 = 0x0F;
+const u_int8_t kBits_00110000 = 0x30;
+const u_int8_t kBits_00111100 = 0x3C;
+const u_int8_t kBits_00111111 = 0x3F;
+const u_int8_t kBits_11000000 = 0xC0;
+const u_int8_t kBits_11110000 = 0xF0;
+const u_int8_t kBits_11111100 = 0xFC;
+
+size_t EstimateBas64EncodedDataSize(size_t inDataSize)
+{
+size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4;
+theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72;
+return(theEncodedDataSize);
+}
+
+size_t EstimateBas64DecodedDataSize(size_t inDataSize)
+{
+size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3;
+//theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72;
+return(theDecodedDataSize);
+}
+
+bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize)
+{
+size_t theEncodedDataSize = EstimateBas64EncodedDataSize(inInputDataSize);
+if (*ioOutputDataSize < theEncodedDataSize)
+ return(false);
+*ioOutputDataSize = theEncodedDataSize;
+const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
+u_int32_t theInIndex = 0, theOutIndex = 0;
+for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3)
+ {
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0];
+ if (theOutIndex % 74 == 72)
+ {
+ outOutputData[theOutIndex++] = '\r';
+ outOutputData[theOutIndex++] = '\n';
+ }
+ }
+const size_t theRemainingBytes = inInputDataSize - theInIndex;
+if (theRemainingBytes == 1)
+ {
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4];
+ outOutputData[theOutIndex++] = '=';
+ outOutputData[theOutIndex++] = '=';
+ if (theOutIndex % 74 == 72)
+ {
+ outOutputData[theOutIndex++] = '\r';
+ outOutputData[theOutIndex++] = '\n';
+ }
+ }
+else if (theRemainingBytes == 2)
+ {
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6];
+ outOutputData[theOutIndex++] = '=';
+ if (theOutIndex % 74 == 72)
+ {
+ outOutputData[theOutIndex++] = '\r';
+ outOutputData[theOutIndex++] = '\n';
+ }
+ }
+return(true);
+}
+
+bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize)
+{
+memset(ioOutputData, '.', *ioOutputDataSize);
+
+size_t theDecodedDataSize = EstimateBas64DecodedDataSize(inInputDataSize);
+if (*ioOutputDataSize < theDecodedDataSize)
+ return(false);
+*ioOutputDataSize = 0;
+const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
+u_int8_t *theOutPtr = (u_int8_t *)ioOutputData;
+size_t theInIndex = 0, theOutIndex = 0;
+u_int8_t theOutputOctet;
+size_t theSequence = 0;
+for (; theInIndex < inInputDataSize; )
+ {
+ int8_t theSextet = 0;
+
+ int8_t theCurrentInputOctet = theInPtr[theInIndex];
+ theSextet = kBase64DecodeTable[theCurrentInputOctet];
+ if (theSextet == -1)
+ break;
+ while (theSextet == -2)
+ {
+ theCurrentInputOctet = theInPtr[++theInIndex];
+ theSextet = kBase64DecodeTable[theCurrentInputOctet];
+ }
+ while (theSextet == -3)
+ {
+ theCurrentInputOctet = theInPtr[++theInIndex];
+ theSextet = kBase64DecodeTable[theCurrentInputOctet];
+ }
+ if (theSequence == 0)
+ {
+ theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 2 & kBits_11111100;
+ }
+ else if (theSequence == 1)
+ {
+ theOutputOctet |= (theSextet >- 0 ? theSextet : 0) >> 4 & kBits_00000011;
+ theOutPtr[theOutIndex++] = theOutputOctet;
+ }
+ else if (theSequence == 2)
+ {
+ theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 4 & kBits_11110000;
+ }
+ else if (theSequence == 3)
+ {
+ theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 2 & kBits_00001111;
+ theOutPtr[theOutIndex++] = theOutputOctet;
+ }
+ else if (theSequence == 4)
+ {
+ theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 6 & kBits_11000000;
+ }
+ else if (theSequence == 5)
+ {
+ theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 0 & kBits_00111111;
+ theOutPtr[theOutIndex++] = theOutputOctet;
+ }
+ theSequence = (theSequence + 1) % 6;
+ if (theSequence != 2 && theSequence != 4)
+ theInIndex++;
+ }
+*ioOutputDataSize = theOutIndex;
+return(true);
+}
View
36 Crypto/.svn/text-base/Base64Transcoder.h.svn-base
@@ -0,0 +1,36 @@
+/*
+ * Base64Transcoder.h
+ * Base64Test
+ *
+ * Created by Jonathan Wight on Tue Mar 18 2003.
+ * Copyright (c) 2003 Toxic Software. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+
+extern size_t EstimateBas64EncodedDataSize(size_t inDataSize);
+extern size_t EstimateBas64DecodedDataSize(size_t inDataSize);
+
+extern bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize);
+extern bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize);
+
View
230 Crypto/Base64Transcoder.c
@@ -0,0 +1,230 @@
+/*
+ * Base64Transcoder.c
+ * Base64Test
+ *
+ * Created by Jonathan Wight on Tue Mar 18 2003.
+ * Copyright (c) 2003 Toxic Software. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include "Base64Transcoder.h"
+
+#include <math.h>
+#include <string.h>
+
+const u_int8_t kBase64EncodeTable[64] = {
+ /* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D',
+ /* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H',
+ /* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L',
+ /* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P',
+ /* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T',
+ /* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X',
+ /* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b',
+ /* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f',
+ /* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j',
+ /* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n',
+ /* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r',
+ /* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v',
+ /* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z',
+ /* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3',
+ /* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7',
+ /* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/'
+};
+
+/*
+-1 = Base64 end of data marker.
+-2 = White space (tabs, cr, lf, space)
+-3 = Noise (all non whitespace, non-base64 characters)
+-4 = Dangerous noise
+-5 = Illegal noise (null byte)
+*/
+
+const int8_t kBase64DecodeTable[128] = {
+ /* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3,
+ /* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3,
+ /* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2,
+ /* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3,
+ /* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3,
+ /* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3,
+ /* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3,
+ /* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3,
+ /* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3,
+ /* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3,
+ /* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62,
+ /* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63,
+ /* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55,
+ /* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59,
+ /* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3,
+ /* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3,
+ /* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2,
+ /* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6,
+ /* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10,
+ /* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14,
+ /* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18,
+ /* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22,
+ /* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3,
+ /* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3,
+ /* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28,
+ /* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32,
+ /* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36,
+ /* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40,
+ /* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44,
+ /* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48,
+ /* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3,
+ /* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3
+};
+
+const u_int8_t kBits_00000011 = 0x03;
+const u_int8_t kBits_00001111 = 0x0F;
+const u_int8_t kBits_00110000 = 0x30;
+const u_int8_t kBits_00111100 = 0x3C;
+const u_int8_t kBits_00111111 = 0x3F;
+const u_int8_t kBits_11000000 = 0xC0;
+const u_int8_t kBits_11110000 = 0xF0;
+const u_int8_t kBits_11111100 = 0xFC;
+
+size_t EstimateBas64EncodedDataSize(size_t inDataSize)
+{
+size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4;
+theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72;
+return(theEncodedDataSize);
+}
+
+size_t EstimateBas64DecodedDataSize(size_t inDataSize)
+{
+size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3;
+//theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72;
+return(theDecodedDataSize);
+}
+
+bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize)
+{
+size_t theEncodedDataSize = EstimateBas64EncodedDataSize(inInputDataSize);
+if (*ioOutputDataSize < theEncodedDataSize)
+ return(false);
+*ioOutputDataSize = theEncodedDataSize;
+const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
+u_int32_t theInIndex = 0, theOutIndex = 0;
+for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3)
+ {
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0];
+ if (theOutIndex % 74 == 72)
+ {
+ outOutputData[theOutIndex++] = '\r';
+ outOutputData[theOutIndex++] = '\n';
+ }
+ }
+const size_t theRemainingBytes = inInputDataSize - theInIndex;
+if (theRemainingBytes == 1)
+ {
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4];
+ outOutputData[theOutIndex++] = '=';
+ outOutputData[theOutIndex++] = '=';
+ if (theOutIndex % 74 == 72)
+ {
+ outOutputData[theOutIndex++] = '\r';
+ outOutputData[theOutIndex++] = '\n';
+ }
+ }
+else if (theRemainingBytes == 2)
+ {
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
+ outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6];
+ outOutputData[theOutIndex++] = '=';
+ if (theOutIndex % 74 == 72)
+ {
+ outOutputData[theOutIndex++] = '\r';
+ outOutputData[theOutIndex++] = '\n';
+ }
+ }
+return(true);
+}
+
+bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize)
+{
+memset(ioOutputData, '.', *ioOutputDataSize);
+
+size_t theDecodedDataSize = EstimateBas64DecodedDataSize(inInputDataSize);
+if (*ioOutputDataSize < theDecodedDataSize)
+ return(false);
+*ioOutputDataSize = 0;
+const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
+u_int8_t *theOutPtr = (u_int8_t *)ioOutputData;
+size_t theInIndex = 0, theOutIndex = 0;
+u_int8_t theOutputOctet;
+size_t theSequence = 0;
+for (; theInIndex < inInputDataSize; )
+ {
+ int8_t theSextet = 0;
+
+ int8_t theCurrentInputOctet = theInPtr[theInIndex];
+ theSextet = kBase64DecodeTable[theCurrentInputOctet];
+ if (theSextet == -1)
+ break;
+ while (theSextet == -2)
+ {
+ theCurrentInputOctet = theInPtr[++theInIndex];
+ theSextet = kBase64DecodeTable[theCurrentInputOctet];
+ }
+ while (theSextet == -3)
+ {
+ theCurrentInputOctet = theInPtr[++theInIndex];
+ theSextet = kBase64DecodeTable[theCurrentInputOctet];
+ }
+ if (theSequence == 0)
+ {
+ theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 2 & kBits_11111100;
+ }
+ else if (theSequence == 1)
+ {
+ theOutputOctet |= (theSextet >- 0 ? theSextet : 0) >> 4 & kBits_00000011;
+ theOutPtr[theOutIndex++] = theOutputOctet;
+ }
+ else if (theSequence == 2)
+ {
+ theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 4 & kBits_11110000;
+ }
+ else if (theSequence == 3)
+ {
+ theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 2 & kBits_00001111;
+ theOutPtr[theOutIndex++] = theOutputOctet;
+ }
+ else if (theSequence == 4)
+ {
+ theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 6 & kBits_11000000;
+ }
+ else if (theSequence == 5)
+ {
+ theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 0 & kBits_00111111;
+ theOutPtr[theOutIndex++] = theOutputOctet;
+ }
+ theSequence = (theSequence + 1) % 6;
+ if (theSequence != 2 && theSequence != 4)
+ theInIndex++;
+ }
+*ioOutputDataSize = theOutIndex;
+return(true);
+}
View
36 Crypto/Base64Transcoder.h
@@ -0,0 +1,36 @@
+/*
+ * Base64Transcoder.h
+ * Base64Test
+ *
+ * Created by Jonathan Wight on Tue Mar 18 2003.
+ * Copyright (c) 2003 Toxic Software. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+
+extern size_t EstimateBas64EncodedDataSize(size_t inDataSize);
+extern size_t EstimateBas64DecodedDataSize(size_t inDataSize);
+
+extern bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize);
+extern bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize);
+
View
11 English.lproj/.svn/all-wcprops
@@ -0,0 +1,11 @@
+K 25
+svn:wc:ra_dav:version-url
+V 56
+/svn/!svn/ver/209/code/obj-c/OAuthConsumer/English.lproj
+END
+InfoPlist.strings
+K 25
+svn:wc:ra_dav:version-url
+V 74
+/svn/!svn/ver/209/code/obj-c/OAuthConsumer/English.lproj/InfoPlist.strings
+END
View
62 English.lproj/.svn/entries
@@ -0,0 +1,62 @@
+10
+
+dir
+1168
+http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/English.lproj
+http://oauth.googlecode.com/svn
+
+
+
+2007-11-02T03:54:59.432759Z
+209
+jon.r.crosby
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+f7ae4463-c52f-0410-a7dc-93bad6e629e8
+
+InfoPlist.strings
+file
+
+
+
+
+2010-02-09T14:46:10.000000Z
+124575f55e1aed7ba744bda371bf3457
+2007-11-02T03:54:59.432759Z
+209
+jon.r.crosby
+has-props
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+200
+
View
5 English.lproj/.svn/prop-base/InfoPlist.strings.svn-base
@@ -0,0 +1,5 @@
+K 13
+svn:mime-type
+V 24
+application/octet-stream
+END
View
BIN English.lproj/.svn/text-base/InfoPlist.strings.svn-base
Binary file not shown.
View
BIN English.lproj/InfoPlist.strings
Binary file not shown.
View
26 Info.plist
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>net.oauth.OAuthConsumer</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>0.1.1</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
View
35 NSMutableURLRequest+Parameters.h
@@ -0,0 +1,35 @@
+//
+// NSMutableURLRequest+Parameters.h
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "OARequestParameter.h"
+#import "NSURL+Base.h"
+
+
+@interface NSMutableURLRequest (OAParameterAdditions)
+
+- (NSArray *)parameters;
+- (void)setParameters:(NSArray *)parameters;
+
+@end
View
92 NSMutableURLRequest+Parameters.m
@@ -0,0 +1,92 @@
+//
+// NSMutableURLRequest+Parameters.m
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "NSMutableURLRequest+Parameters.h"
+
+
+@implementation NSMutableURLRequest (OAParameterAdditions)
+
+- (NSArray *)parameters
+{
+ NSString *encodedParameters;
+ BOOL shouldfree = NO;
+
+ if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"])
+ encodedParameters = [[self URL] query];
+ else
+ {
+ // POST, PUT
+ shouldfree = YES;
+ encodedParameters = [[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding];
+ }
+
+ if ((encodedParameters == nil) || ([encodedParameters isEqualToString:@""]))
+ return nil;
+
+ NSArray *encodedParameterPairs = [encodedParameters componentsSeparatedByString:@"&"];
+ NSMutableArray *requestParameters = [[NSMutableArray alloc] initWithCapacity:16];
+
+ for (NSString *encodedPair in encodedParameterPairs)
+ {
+ NSArray *encodedPairElements = [encodedPair componentsSeparatedByString:@"="];
+ OARequestParameter *parameter = [OARequestParameter requestParameterWithName:[[encodedPairElements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
+ value:[[encodedPairElements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ [requestParameters addObject:parameter];
+ }
+
+ // Cleanup
+ if (shouldfree)
+ [encodedParameters release];
+
+ return [requestParameters autorelease];
+}
+
+- (void)setParameters:(NSArray *)parameters
+{
+ NSMutableString *encodedParameterPairs = [NSMutableString stringWithCapacity:256];
+
+ int position = 1;
+ for (OARequestParameter *requestParameter in parameters)
+ {
+ [encodedParameterPairs appendString:[requestParameter URLEncodedNameValuePair]];
+ if (position < [parameters count])
+ [encodedParameterPairs appendString:@"&"];
+
+ position++;
+ }
+
+ if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"])
+ [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", [[self URL] URLStringWithoutQuery], encodedParameterPairs]]];
+ else
+ {
+ // POST, PUT
+ NSData *postData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
+ [self setHTTPBody:postData];
+ [self setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
+ [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
+ }
+}
+
+@end
View
53 NSMutableURLRequest+ParametersTest.h
@@ -0,0 +1,53 @@
+//
+// NSMutableURLRequest+ParametersTest.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "NSMutableURLRequest+Parameters.h"
+
+@interface NSMutableURLRequest_ParametersTest : SenTestCase {
+ NSMutableURLRequest *requestWithoutParams;
+ NSMutableURLRequest *requestWithQueryParams;
+ NSMutableURLRequest *requestWithBodyParams;
+ NSArray *parameters;
+}
+
+- (void)testParametersForGETWithoutParameters;
+- (void)testParametersForGETWithParameters;
+- (void)testParametersForPOSTWithoutParameters;
+- (void)testParametersForPOSTWithParameters;
+- (void)testParametersForPUTWithoutParameters;
+- (void)testParametersForPUTWithParameters;
+- (void)testParametersForDELETEWithoutParameters;
+- (void)testParametersForDELETEWithParameters;
+- (void)testSetParametersForGETWithoutParameters;
+- (void)testSetParametersForGETWithParameters;
+- (void)testSetParametersForPOSTWithoutParameters;
+- (void)testSetParametersForPOSTWithParameters;
+- (void)testSetParametersForPUTWithoutParameters;
+- (void)testSetParametersForPUTWithParameters;
+- (void)testSetParametersForDELETEWithoutParameters;
+- (void)testSetParametersForDELETEWithParameters;
+
+@end
View
185 NSMutableURLRequest+ParametersTest.m
@@ -0,0 +1,185 @@
+//
+// NSMutableURLRequest+ParametersTest.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "NSMutableURLRequest+ParametersTest.h"
+
+@interface NSMutableURLRequest_ParametersTest (Utility)
+- (void)verifyDefaultParametersForRequest:(NSMutableURLRequest *)request;
+- (void)verifyModifiedParametersForRequest:(NSMutableURLRequest *)request;
+- (void)verifyEmptyParametersForRequest:(NSMutableURLRequest *)request;
+@end
+
+@implementation NSMutableURLRequest_ParametersTest
+
+- (void)setUp {
+ requestWithoutParams = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://kaboomerang.com/index.html"]];
+ requestWithQueryParams = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://kaboomerang.com/test.rb?first_name=fake&last_name=steve"]];
+
+ NSString *encodedParameterPairs = @"first_name=fake&last_name=steve";
+ NSData *requestData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
+
+ requestWithBodyParams = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://kaboomerang.com/test.rb"]];
+ [requestWithBodyParams setHTTPBody:requestData];
+ [requestWithBodyParams setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
+ [requestWithBodyParams setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
+
+ OARequestParameter *firstName = [[OARequestParameter alloc] initWithName:@"address" value:@"123 Main Street"];
+ OARequestParameter *lastName = [[OARequestParameter alloc] initWithName:@"city" value:@"Hometown"];
+ parameters = [NSArray arrayWithObjects:firstName, lastName, nil];
+}
+
+- (void)testParametersForGETWithoutParameters {
+ [self verifyEmptyParametersForRequest:requestWithoutParams];
+}
+
+- (void)testParametersForGETWithParameters {
+ [self verifyDefaultParametersForRequest:requestWithQueryParams];
+}
+
+- (void)testParametersForPOSTWithoutParameters {
+ [requestWithoutParams setHTTPMethod:@"POST"];
+ [self verifyEmptyParametersForRequest:requestWithoutParams];
+}
+
+- (void)testParametersForPOSTWithParameters {
+ [requestWithBodyParams setHTTPMethod:@"POST"];
+ [self verifyDefaultParametersForRequest:requestWithBodyParams];
+}
+
+- (void)testParametersForPUTWithoutParameters {
+ [requestWithoutParams setHTTPMethod:@"PUT"];
+ [self verifyEmptyParametersForRequest:requestWithoutParams];
+}
+
+- (void)testParametersForPUTWithParameters {
+ [requestWithBodyParams setHTTPMethod:@"PUT"];
+ [self verifyDefaultParametersForRequest:requestWithBodyParams];
+}
+
+- (void)testParametersForDELETEWithoutParameters {
+ [requestWithoutParams setHTTPMethod:@"DELETE"];
+ [self verifyEmptyParametersForRequest:requestWithoutParams];
+}
+
+- (void)testParametersForDELETEWithParameters {
+ [requestWithQueryParams setHTTPMethod:@"DELETE"];
+ [self verifyDefaultParametersForRequest:requestWithQueryParams];
+}
+
+- (void)testSetParametersForGETWithoutParameters {
+ [requestWithoutParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithoutParams];
+}
+
+- (void)testSetParametersForGETWithParameters {
+ [requestWithQueryParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithQueryParams];
+}
+
+- (void)testSetParametersForPOSTWithoutParameters {
+ [requestWithoutParams setHTTPMethod:@"POST"];
+ [requestWithoutParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithoutParams];
+}
+
+- (void)testSetParametersForPOSTWithParameters {
+ [requestWithBodyParams setHTTPMethod:@"POST"];
+ [requestWithBodyParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithBodyParams];
+}
+
+- (void)testSetParametersForPUTWithoutParameters {
+ [requestWithoutParams setHTTPMethod:@"PUT"];
+ [requestWithoutParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithoutParams];
+}
+
+- (void)testSetParametersForPUTWithParameters {
+ [requestWithBodyParams setHTTPMethod:@"PUT"];
+ [requestWithBodyParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithBodyParams];
+}
+
+- (void)testSetParametersForDELETEWithoutParameters {
+ [requestWithoutParams setHTTPMethod:@"DELETE"];
+ [requestWithoutParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithoutParams];
+}
+
+- (void)testSetParametersForDELETEWithParameters {
+ [requestWithQueryParams setHTTPMethod:@"DELETE"];
+ [requestWithQueryParams setParameters:parameters];
+ [self verifyModifiedParametersForRequest:requestWithQueryParams];
+}
+
+- (void)verifyDefaultParametersForRequest:(NSMutableURLRequest *)request {
+ STAssertNotNil([request parameters],
+ @"A request with parameters should not return nil.");
+ STAssertEqualObjects([[[request parameters] objectAtIndex:0] name],
+ @"first_name",
+ @"first_name param returned: %@. Expected: first_name.",
+ [[[request parameters] objectAtIndex:0] name]);
+ STAssertEqualObjects([[[request parameters] objectAtIndex:0] value],
+ @"fake",
+ @"first_name param value returned: %@. Expected: fake.",
+ [[[request parameters] objectAtIndex:0] value]);
+ STAssertEqualObjects([[[request parameters] objectAtIndex:1] name],
+ @"last_name",
+ @"last_name param returned: %@. Expected: last_name.",
+ [[[request parameters] objectAtIndex:1] name]);
+ STAssertEqualObjects([[[request parameters] objectAtIndex:1] value],
+ @"steve",
+ @"last_name param value returned: %@. Expected: steve.",
+ [[[request parameters] objectAtIndex:1] value]);
+}
+
+- (void)verifyModifiedParametersForRequest:(NSMutableURLRequest *)request {
+ STAssertNotNil([request parameters],
+ @"A request with parameters should not return nil.");
+ STAssertEqualObjects([[[request parameters] objectAtIndex:0] name],
+ @"address",
+ @"address param returned: %@. Expected: address.",
+ [[[request parameters] objectAtIndex:0] name]);
+ STAssertEqualObjects([[[request parameters] objectAtIndex:0] value],
+ @"123 Main Street",
+ @"address param value returned: %@. Expected: 123 Main Street.",
+ [[[request parameters] objectAtIndex:0] value]);
+ STAssertEqualObjects([[[request parameters] objectAtIndex:1] name],
+ @"city",
+ @"city param returned: %@. Expected: city.",
+ [[[request parameters] objectAtIndex:1] name]);
+ STAssertEqualObjects([[[request parameters] objectAtIndex:1] value],
+ @"Hometown",
+ @"city param value returned: %@. Expected: Hometown.",
+ [[[request parameters] objectAtIndex:1] value]);
+}
+
+- (void)verifyEmptyParametersForRequest:(NSMutableURLRequest *)request {
+ STAssertNil([request parameters],
+ @"A request with no parameters returned: %@",
+ [request parameters]);
+}
+
+@end
View
34 NSString+URLEncoding.h
@@ -0,0 +1,34 @@
+//
+// NSString+URLEncoding.h
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSString (OAURLEncodingAdditions)
+
+- (NSString *)URLEncodedString;
+- (NSString *)URLDecodedString;
+
+@end
View
52 NSString+URLEncoding.m
@@ -0,0 +1,52 @@
+//
+// NSString+URLEncoding.m
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "NSString+URLEncoding.h"
+
+
+@implementation NSString (OAURLEncodingAdditions)
+
+- (NSString *)URLEncodedString
+{
+ NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
+ (CFStringRef)self,
+ NULL,
+ CFSTR("!*'();:@&=+$,/?%#[]"),
+ kCFStringEncodingUTF8);
+ [result autorelease];
+ return result;
+}
+
+- (NSString*)URLDecodedString
+{
+ NSString *result = (NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
+ (CFStringRef)self,
+ CFSTR(""),
+ kCFStringEncodingUTF8);
+ [result autorelease];
+ return result;
+}
+
+@end
View
33 NSString+URLEncodingTest.h
@@ -0,0 +1,33 @@
+//
+// NSString+URLEncodingTest.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "NSString+URLEncoding.h"
+
+@interface NSString_URLEncodingTest : SenTestCase
+
+- (void)testURLEncodedString;
+
+@end
View
38 NSString+URLEncodingTest.m
@@ -0,0 +1,38 @@
+//
+// NSString+URLEncodingTest.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "NSString+URLEncodingTest.h"
+
+
+@implementation NSString_URLEncodingTest
+
+- (void)testURLEncodedString {
+ //TODO gather complete set of test chars -> encoded values
+ NSString *starter = @"\"<>\%{}[]|\\^`hello #";
+ STAssertEqualObjects([starter URLEncodedString], @"\%22\%3C\%3E\%25\%7B\%7D\%5B\%5D\%7C\%5C\%5E\%60hello\%20\%23", @"The string was not encoded properly.");
+}
+
+@end
View
34 NSURL+Base.h
@@ -0,0 +1,34 @@
+//
+// NSURL+Base.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSURL (OABaseAdditions)
+
+- (NSString *)URLStringWithoutQuery;
+
+@end
View
38 NSURL+Base.m
@@ -0,0 +1,38 @@
+//
+// NSURL+Base.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "NSURL+Base.h"
+
+
+@implementation NSURL (OABaseAdditions)
+
+- (NSString *)URLStringWithoutQuery
+{
+ NSArray *parts = [[self absoluteString] componentsSeparatedByString:@"?"];
+ return [parts objectAtIndex:0];
+}
+
+@end
View
35 NSURL+BaseTest.h
@@ -0,0 +1,35 @@
+//
+// NSURL+BaseTest.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "NSURL+Base.h"
+
+
+@interface NSURL_BaseTest : SenTestCase
+
+- (void)testURLStringWithoutQuery;
+
+@end
View
39 NSURL+BaseTest.m
@@ -0,0 +1,39 @@
+//
+// NSURL+BaseTest.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "NSURL+BaseTest.h"
+
+
+@implementation NSURL_BaseTest
+
+- (void)testURLStringWithoutQuery {
+ STAssertEqualObjects([[NSURL URLWithString:@"http://example.com"] URLStringWithoutQuery], @"http://example.com", NULL);
+ STAssertEqualObjects([[NSURL URLWithString:@"http://example.com/file.html"] URLStringWithoutQuery], @"http://example.com/file.html", NULL);
+ STAssertEqualObjects([[NSURL URLWithString:@"http://example.com/?name=bob"] URLStringWithoutQuery], @"http://example.com/", NULL);
+ STAssertEqualObjects([[NSURL URLWithString:@"http://example.com/file.rb?name=bob"] URLStringWithoutQuery], @"http://example.com/file.rb", NULL);
+}
+
+@end
View
45 OAAsynchronousDataFetcher.h
@@ -0,0 +1,45 @@
+//
+// OAAsynchronousDataFetcher.h
+// OAuthConsumer
+//
+// Created by Zsombor Szabó on 12/3/08.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+
+#import "OAMutableURLRequest.h"
+
+@interface OAAsynchronousDataFetcher : NSObject {
+ OAMutableURLRequest *request;
+ NSURLResponse *response;
+ NSURLConnection *connection;
+ NSMutableData *responseData;
+ id delegate;
+ SEL didFinishSelector;
+ SEL didFailSelector;
+}
+
++ (id)asynchronousFetcherWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector;
+- (id)initWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector;
+
+- (void)start;
+- (void)cancel;
+
+@end
View
134 OAAsynchronousDataFetcher.m
@@ -0,0 +1,134 @@
+//
+// OAAsynchronousDataFetcher.m
+// OAuthConsumer
+//
+// Created by Zsombor Szabó on 12/3/08.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "OAAsynchronousDataFetcher.h"
+
+#import "OAServiceTicket.h"
+
+@implementation OAAsynchronousDataFetcher
+
++ (id)asynchronousFetcherWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector
+{
+ return [[[OAAsynchronousDataFetcher alloc] initWithRequest:aRequest delegate:aDelegate didFinishSelector:finishSelector didFailSelector:failSelector] autorelease];
+}
+
+- (id)initWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector
+{
+ if (self = [super init])
+ {
+ request = [aRequest retain];
+ delegate = aDelegate;
+ didFinishSelector = finishSelector;
+ didFailSelector = failSelector;
+ }
+ return self;
+}
+
+- (void)start
+{
+ [request prepare];
+
+ if (connection)
+ [connection release];
+
+ connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
+
+ if (connection)
+ {
+ if (responseData)
+ [responseData release];
+ responseData = [[NSMutableData data] retain];
+ }
+ else
+ {
+ OAServiceTicket *ticket= [[OAServiceTicket alloc] initWithRequest:request
+ response:nil
+ didSucceed:NO];
+ [delegate performSelector:didFailSelector
+ withObject:ticket
+ withObject:nil];
+ [ticket release];
+ }
+}
+
+- (void)cancel
+{
+ if (connection)
+ {
+ [connection cancel];
+ [connection release];
+ connection = nil;
+ }
+}
+
+- (void)dealloc
+{
+ if (request) [request release];
+ if (connection) [connection release];
+ if (response) [response release];
+ if (responseData) [responseData release];
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark NSURLConnection methods
+
+- (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)aResponse
+{
+ if (response)
+ [response release];
+ response = [aResponse retain];
+ [responseData setLength:0];
+}
+
+- (void)connection:(NSURLConnection *)aConnection didReceiveData:(NSData *)data
+{
+ [responseData appendData:data];
+}
+
+- (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error
+{
+ OAServiceTicket *ticket= [[OAServiceTicket alloc] initWithRequest:request
+ response:response
+ didSucceed:NO];
+ [delegate performSelector:didFailSelector
+ withObject:ticket
+ withObject:error];
+
+ [ticket release];
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)aConnection
+{
+ OAServiceTicket *ticket = [[OAServiceTicket alloc] initWithRequest:request
+ response:response
+ didSucceed:[(NSHTTPURLResponse *)response statusCode] < 400];
+ [delegate performSelector:didFinishSelector
+ withObject:ticket
+ withObject:responseData];
+
+ [ticket release];
+}
+
+@end
View
40 OAConsumer.h
@@ -0,0 +1,40 @@
+//
+// OAConsumer.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <Foundation/Foundation.h>
+
+
+@interface OAConsumer : NSObject {
+@protected
+ NSString *key;
+ NSString *secret;
+}
+@property(retain) NSString *key;
+@property(retain) NSString *secret;
+
+- (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret;
+
+@end
View
51 OAConsumer.m
@@ -0,0 +1,51 @@
+//
+// OAConsumer.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import "OAConsumer.h"
+
+
+@implementation OAConsumer
+@synthesize key, secret;
+
+#pragma mark init
+
+- (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret
+{
+ if (self = [super init])
+ {
+ self.key = aKey;
+ self.secret = aSecret;
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [key release];
+ [secret release];
+ [super dealloc];
+}
+
+@end
View
35 OAConsumerTest.h
@@ -0,0 +1,35 @@
+//
+// OAConsumerTest.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "OAConsumer.h"
+
+
+@interface OAConsumerTest : SenTestCase
+
+- (void)testInitWithKey;
+
+@end
View
38 OAConsumerTest.m
@@ -0,0 +1,38 @@
+//
+// OAConsumerTest.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "OAConsumerTest.h"
+
+
+@implementation OAConsumerTest
+
+- (void)testInitWithKey {
+ OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"123456" secret:@"abcdef"];
+ STAssertEquals(consumer.key, @"123456", @"Consumer key was incorrectly set to: %@", consumer.key);
+ STAssertEquals(consumer.secret, @"abcdef", @"Consumer secret was incorrectly set to: %@", consumer.secret);
+}
+
+@end
View
45 OADataFetcher.h
@@ -0,0 +1,45 @@
+//
+// OADataFetcher.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 11/5/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "OAMutableURLRequest.h"
+#import "OAServiceTicket.h"
+
+
+@interface OADataFetcher : NSObject {
+@private
+ OAMutableURLRequest *request;
+ NSURLResponse *response;
+ NSURLConnection *connection;
+ NSError *error;
+ NSData *responseData;
+ id delegate;
+ SEL didFinishSelector;
+ SEL didFailSelector;
+}
+
+- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector;
+
+@end
View
65 OADataFetcher.m
@@ -0,0 +1,65 @@
+//
+// OADataFetcher.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 11/5/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "OADataFetcher.h"
+
+
+@implementation OADataFetcher
+
+- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest
+ delegate:(id)aDelegate
+ didFinishSelector:(SEL)finishSelector
+ didFailSelector:(SEL)failSelector
+{
+ request = aRequest;
+ delegate = aDelegate;
+ didFinishSelector = finishSelector;
+ didFailSelector = failSelector;
+
+ [request prepare];
+
+ responseData = [NSURLConnection sendSynchronousRequest:request
+ returningResponse:&response
+ error:&error];
+
+ if (response == nil || responseData == nil || error != nil) {
+ OAServiceTicket *ticket= [[OAServiceTicket alloc] initWithRequest:request
+ response:response
+ didSucceed:NO];
+ [delegate performSelector:didFailSelector
+ withObject:ticket
+ withObject:error];
+ } else {
+ OAServiceTicket *ticket = [[OAServiceTicket alloc] initWithRequest:request
+ response:response
+ didSucceed:[(NSHTTPURLResponse *)response statusCode] < 400];
+ [delegate performSelector:didFinishSelector
+ withObject:ticket
+ withObject:responseData];
+ }
+}
+
+@end
View
38 OADataFetcherTest.h
@@ -0,0 +1,38 @@
+//
+// OADataFetcherTest.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 11/6/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "OADataFetcher.h"
+#import "OAPlaintextSignatureProvider.h"
+
+
+@interface OADataFetcherTest : SenTestCase {
+ NSTask *server;
+}
+
+- (void)testFetchDataWithRequest;
+
+@end
View
78 OADataFetcherTest.m
@@ -0,0 +1,78 @@
+//
+// OADataFetcherTest.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 11/6/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "OADataFetcherTest.h"
+
+
+@implementation OADataFetcherTest
+
+- (void)setUp {
+ NSString *currentDir = [[NSFileManager defaultManager] currentDirectoryPath];
+ NSString *serverPath = [currentDir stringByAppendingPathComponent:@"OATestServer.rb"];
+
+ server = [[NSTask alloc] init];
+ [server setArguments:[NSArray arrayWithObject:serverPath]];
+ [server setLaunchPath:@"/usr/bin/ruby"];
+ [server launch];
+ sleep(2); // let the server get ready to respond
+}
+
+- (void)tearDown {
+ [server terminate];
+}
+
+- (void)testFetchDataWithRequest {
+ OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"dpf43f3p2l4k3l03"
+ secret:@"kd94hf93k423kf44"];
+ NSURL *url = [NSURL URLWithString:@"http://localhost:4567/request_token"];
+ OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
+ consumer:consumer
+ token:NULL
+ realm:NULL
+ signatureProvider:[[OAPlaintextSignatureProvider alloc] init]];
+ [request setHTTPMethod:@"POST"];
+
+ OADataFetcher *fetcher = [[OADataFetcher alloc] init];
+ [fetcher fetchDataWithRequest:request
+ delegate:self
+ didFinishSelector:@selector(requestTokenTicket:finishedWithData:)
+ didFailSelector:@selector(requestTokenTicket:failedWithError:)];
+}
+
+- (void)requestTokenTicket:(OAServiceTicket *)ticket finishedWithData:(NSMutableData *)data {
+ STAssertTrue(ticket.didSucceed, NULL);
+ NSString *responseBody = [[NSString alloc] initWithData:data
+ encoding:NSUTF8StringEncoding];
+ OAToken *token = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
+ STAssertEqualObjects(token.key, @"nnch734d00sl2jdk", NULL);
+ STAssertEqualObjects(token.secret, @"pfkkdhi9sl3r4s00", NULL);
+}
+
+- (void)requestTokenTicket:(OAServiceTicket *)ticket failedWithError:(NSError *)error {
+ STAssertFalse(ticket.didSucceed, NULL);
+}
+
+@end
View
32 OAHMAC_SHA1SignatureProvider.h
@@ -0,0 +1,32 @@
+//
+// OAHMAC_SHA1SignatureProvider.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <Foundation/Foundation.h>
+#import "OASignatureProviding.h"
+
+
+@interface OAHMAC_SHA1SignatureProvider : NSObject <OASignatureProviding>
+@end
View
58 OAHMAC_SHA1SignatureProvider.m
@@ -0,0 +1,58 @@
+//
+// OAHMAC_SHA1SignatureProvider.m
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "OAHMAC_SHA1SignatureProvider.h"
+#import <CommonCrypto/CommonHMAC.h>
+
+#include "Base64Transcoder.h"
+
+@implementation OAHMAC_SHA1SignatureProvider
+
+- (NSString *)name
+{
+ return @"HMAC-SHA1";
+}
+
+- (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret
+{
+ NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *clearTextData = [text dataUsingEncoding:NSUTF8StringEncoding];
+ unsigned char result[20];
+ CCHmac(kCCHmacAlgSHA1, [secretData bytes], [secretData length], [clearTextData bytes], [clearTextData length], result);
+
+ //Base64 Encoding
+
+ char base64Result[32];
+ size_t theResultLength = 32;
+ Base64EncodeData(result, 20, base64Result, &theResultLength);
+ NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength];
+
+ NSString *base64EncodedResult = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
+
+ return [base64EncodedResult autorelease];
+}
+
+@end
View
34 OAHMAC_SHA1SignatureProviderTest.h
@@ -0,0 +1,34 @@
+//
+// OAHMAC_SHA1SignatureProviderTest.h
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <SenTestingKit/SenTestingKit.h>
+#import "OAHMAC_SHA1SignatureProvider.h"
+
+
+@interface OAHMAC_SHA1SignatureProviderTest : SenTestCase
+
+- (void)testSignClearText;
+
+@end
View
42 OAHMAC_SHA1SignatureProviderTest.m
@@ -0,0 +1,42 @@
+//
+// OAHMAC_SHA1SignatureProviderTest.m
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import "OAHMAC_SHA1SignatureProviderTest.h"
+
+
+@implementation OAHMAC_SHA1SignatureProviderTest
+
+- (void)testSignClearText {
+ OAHMAC_SHA1SignatureProvider *provider = [[OAHMAC_SHA1SignatureProvider alloc] init];
+ STAssertEqualObjects([provider signClearText:@"simon says" withSecret:@"abcedfg123456789"],
+ @"vyeIZc3+tF6F3i95IEV+AJCWBYQ=",
+ NULL);
+ STAssertEqualObjects([provider signClearText:@"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal&kd94hf93k423kf44&pfkkdhi9sl3r4s00"
+ withSecret:@"kd94hf93k423kf44&pfkkdhi9sl3r4s00"],
+ @"Gcg/323lvAsQ707p+y41y14qWfY=",
+ NULL);
+}
+
+@end
View
68 OAMutableURLRequest.h
@@ -0,0 +1,68 @@
+//
+// OAMutableURLRequest.h
+// OAuthConsumer
+//
+// Created by Jon Crosby on 10/19/07.
+// Copyright 2007 Kaboomerang LLC. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+
+#import <Foundation/Foundation.h>
+#import "OAConsumer.h"
+#import "OAToken.h"
+#import "OAHMAC_SHA1SignatureProvider.h"
+#import "OASignatureProviding.h"
+#import "NSMutableURLRequest+Parameters.h"
+#import "NSURL+Base.h"
+
+
+@interface OAMutableURLRequest : NSMutableURLRequest {
+@protected
+ OAConsumer *consumer;
+ OAToken *token;