Issue:
[FEATURE] Validate card security codes and expiration month/year

### Feature Description

As of now, we don't perform any validations on card security codes (CVC/CVV/CID code) and card expiration month and year. It'd be great if the following validations can be done:

1. Card security code must be 3 or 4 digits only
2. Expiration month is valid (1-12)
3. Expiration year is a 4 digit number only
4. Card has not expired (expiration month and year correspond to a date in the future)

This logic can reside in a new crate called `cards`. Please also include unit tests in your PR.

_For external contributors, clarify any questions you may have, and let us know that you're interested in picking this up. We'll assign this issue to you to reduce duplication of effort on the same task._

### Possible Implementation

For card security codes, you could do:

```rust
use masking::StrongSecret;

struct CardSecurityCode(StrongSecret<u16>);

let card_security_code = CardSecurityCode::try_from(123); // You can use the `TryFrom` trait for this purpose

struct CardExpirationMonth(StrongSecret<u8>);

let card_expiration_month = CardExpirationMonth::try_from(1); // You can use the `TryFrom` trait for this purpose

impl CardExpirationMonth {
    fn inner(&self) -> u8;
    fn two_digits(&self) -> String;
}

struct CardExpirationYear(StrongSecret<u16>);

let card_expiration_year = CardExpirationYear::try_from(2038); // You can use the `TryFrom` trait for this purpose

impl CardExpirationYear {
    fn inner(&self) -> u16;
    fn four_digits(&self) -> String;
    fn two_digits(&self) -> String;
}

struct CardExpiration {
    pub month: CardExpirationMonth,
    pub year: CardExpirationYear,
}

impl CardExpiration {
    fn is_expired(&self) -> bool;
}
```

You can implement `Serialize` and `Deserialize` traits on `CardSecurityCode`. Use the 2-digit and 4-digit representations for the month and year, respectively, for the `Serialize` and `Deserialize` implementations of the card expiry month and year. You can implement any more methods as necessary.

### Have you spent some time to check if this feature request has been raised before?

- [X] I checked and didn't find similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

None

Resolution:
<think>
PR Context:
- Title: feat(cards): validate card security code and expiration
- Merged: 2023-05-03T01:54:31Z
- Files changed: 5 files
- Commits: 11 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [x] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates

## Description
Add basic validations for card security codes (CVC/CVV/CID code) and card expiration month and year. This logic resides in a new crate called cards. Validations included (as of now):
 - [x] Card security code must be 3 or 4 digits only
 - [x] Expiration month is valid (1-12)
 - [x] Expiration year is a 4 digit numb
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** feat(cards): validate card security code and expiration (#874)
Co-authored-by: Sanchith Hegde <22217
Files to modify:


**crates/cards/src/lib.rs**
  Add:
    - function: private::try_from
    - function: private::deserialize
    - function: pub::two_digits
    - function: private::try_from
    - function: private::deserialize
    - function: pub::four_digits
    - function: pub::two_digits
    - function: private::try_from
    - function: private::deserialize
    - function: pub::is_expired
    - function: pub::get_month
    - function: pub::get_year
    - function: private::try_from
    - function: private::deref
    - function: private::deref
    - function: private::deref
    - struct: pub::CardSecurityCode
    - struct: pub::CardExpirationMonth
    - struct: pub::CardExpirationYear
    - struct: pub::CardExpiration
    - impl: impl TryFrom<u16> for CardSecurityCode
    - impl: impl Deserialize<'de> for CardSecurityCode
    - impl: impl CardExpirationMonth
    - impl: impl TryFrom<u8> for CardExpirationMonth
    - impl: impl Deserialize<'de> for CardExpirationMonth
    - impl: impl CardExpirationYear
    - impl: impl TryFrom<u16> for CardExpirationYear
    - impl: impl Deserialize<'de> for CardExpirationYear
    - impl: impl CardExpiration
    - impl: impl TryFrom<(u8, u16)> for CardExpiration
    - impl: impl Deref for CardSecurityCode
    - impl: impl Deref for CardExpirationMonth
    - impl: impl Deref for CardExpirationYear

**crates/cards/tests/basic.rs**
  Add:
    - function: private::test_card_security_code
    - function: private::test_card_expiration_month
    - function: private::test_card_expiration_year
    - function: private::test_card_expiration

**crates/masking/src/serde.rs**
  Add:
    - impl: impl SerializableSecret for u8
    - impl: impl SerializableSecret for u16