Skip to main content

iso8583_core/
field.rs

1//! ISO 8583 Field Definitions
2//!
3//! This module defines all 128 fields of the ISO 8583 standard with their:
4//! - Field number
5//! - Field type (numeric, alphanumeric, binary, etc.)
6//! - Length specification (fixed or variable)
7//! - Validation rules
8
9use crate::error::{ISO8583Error, Result};
10use std::fmt;
11
12/// ISO 8583 Field enumeration
13#[allow(missing_docs)]
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[repr(u8)]
16pub enum Field {
17    // Field 1 is the secondary bitmap (handled specially)
18    SecondaryBitmap = 1,
19
20    // Fields 2-128
21    PrimaryAccountNumber = 2,
22    ProcessingCode = 3,
23    TransactionAmount = 4,
24    SettlementAmount = 5,
25    CardholderBillingAmount = 6,
26    TransmissionDateTime = 7,
27    CardholderBillingFeeAmount = 8,
28    SettlementConversionRate = 9,
29    CardholderBillingConversionRate = 10,
30    SystemTraceAuditNumber = 11,
31    LocalTransactionTime = 12,
32    LocalTransactionDate = 13,
33    ExpirationDate = 14,
34    SettlementDate = 15,
35    CurrencyConversionDate = 16,
36    CaptureDate = 17,
37    MerchantType = 18,
38    AcquiringInstitutionCountryCode = 19,
39    PANExtendedCountryCode = 20,
40    ForwardingInstitutionCountryCode = 21,
41    PointOfServiceEntryMode = 22,
42    ApplicationPANSequenceNumber = 23,
43    NetworkInternationalIdentifier = 24,
44    PointOfServiceConditionCode = 25,
45    PointOfServiceCaptureCode = 26,
46    AuthorizingIdentificationResponseLength = 27,
47    TransactionFeeAmount = 28,
48    SettlementFeeAmount = 29,
49    TransactionProcessingFeeAmount = 30,
50    SettlementProcessingFeeAmount = 31,
51    AcquiringInstitutionIdentificationCode = 32,
52    ForwardingInstitutionIdentificationCode = 33,
53    ExtendedPrimaryAccountNumber = 34,
54    Track2Data = 35,
55    Track3Data = 36,
56    RetrievalReferenceNumber = 37,
57    AuthorizationIdentificationResponse = 38,
58    ResponseCode = 39,
59    ServiceRestrictionCode = 40,
60    CardAcceptorTerminalIdentification = 41,
61    CardAcceptorIdentificationCode = 42,
62    CardAcceptorNameLocation = 43,
63    AdditionalResponseData = 44,
64    Track1Data = 45,
65    AdditionalDataISO = 46,
66    AdditionalDataNational = 47,
67    AdditionalDataPrivate = 48,
68    CurrencyCodeTransaction = 49,
69    CurrencyCodeSettlement = 50,
70    CurrencyCodeCardholderBilling = 51,
71    PersonalIdentificationNumberData = 52,
72    SecurityRelatedControlInformation = 53,
73    AdditionalAmounts = 54,
74    ReservedISO1 = 55,
75    ReservedISO2 = 56,
76    ReservedNational1 = 57,
77    ReservedNational2 = 58,
78    ReservedNational3 = 59,
79    ReservedPrivate1 = 60,
80    ReservedPrivate2 = 61,
81    ReservedPrivate3 = 62,
82    ReservedPrivate4 = 63,
83    MessageAuthenticationCode = 64,
84    // Field 65 is tertiary bitmap
85    TertiaryBitmap = 65,
86    SettlementCode = 66,
87    ExtendedPaymentCode = 67,
88    ReceivingInstitutionCountryCode = 68,
89    SettlementInstitutionCountryCode = 69,
90    NetworkManagementInformationCode = 70,
91    MessageNumber = 71,
92    MessageNumberLast = 72,
93    DateAction = 73,
94    CreditsNumber = 74,
95    CreditsReversalNumber = 75,
96    DebitsNumber = 76,
97    DebitsReversalNumber = 77,
98    TransferNumber = 78,
99    TransferReversalNumber = 79,
100    InquiriesNumber = 80,
101    AuthorizationsNumber = 81,
102    CreditsProcessingFeeAmount = 82,
103    CreditsTransactionFeeAmount = 83,
104    DebitsProcessingFeeAmount = 84,
105    DebitsTransactionFeeAmount = 85,
106    CreditsAmount = 86,
107    CreditsReversalAmount = 87,
108    DebitsAmount = 88,
109    DebitsReversalAmount = 89,
110    OriginalDataElements = 90,
111    FileUpdateCode = 91,
112    FileSecurityCode = 92,
113    ResponseIndicator = 93,
114    ServiceIndicator = 94,
115    ReplacementAmounts = 95,
116    MessageSecurityCode = 96,
117    NetSettlementAmount = 97,
118    Payee = 98,
119    SettlementInstitutionIdentificationCode = 99,
120    ReceivingInstitutionIdentificationCode = 100,
121    FileName = 101,
122    AccountIdentification1 = 102,
123    AccountIdentification2 = 103,
124    TransactionDescription = 104,
125    ReservedISO3 = 105,
126    ReservedISO4 = 106,
127    ReservedISO5 = 107,
128    ReservedISO6 = 108,
129    ReservedISO7 = 109,
130    ReservedISO8 = 110,
131    ReservedISO9 = 111,
132    ReservedNational4 = 112,
133    ReservedNational5 = 113,
134    ReservedNational6 = 114,
135    ReservedNational7 = 115,
136    ReservedNational8 = 116,
137    ReservedNational9 = 117,
138    ReservedNational10 = 118,
139    ReservedNational11 = 119,
140    ReservedPrivate5 = 120,
141    ReservedPrivate6 = 121,
142    ReservedPrivate7 = 122,
143    ReservedPrivate8 = 123,
144    InfoText = 124,
145    NetworkManagementInformation = 125,
146    IssuerTraceId = 126,
147    ReservedPrivate9 = 127,
148    MessageAuthenticationCode2 = 128,
149}
150
151/// Field type enumeration
152#[derive(Debug, Clone, Copy, PartialEq, Eq)]
153pub enum FieldType {
154    /// Numeric (n)
155    Numeric,
156    /// Alpha (a)
157    Alpha,
158    /// Alphanumeric (an)
159    AlphaNumeric,
160    /// Alphanumeric + special (ans)
161    AlphaNumericSpecial,
162    /// Binary (b)
163    Binary,
164    /// Track 2 format (z)
165    Track2,
166    /// Track 3 format (x+n)
167    Track3,
168}
169
170/// Field length specification
171#[derive(Debug, Clone, Copy, PartialEq, Eq)]
172pub enum FieldLength {
173    /// Fixed length
174    Fixed(usize),
175    /// Variable length with 2-digit length indicator (LLVAR)
176    LLVar(usize), // max length
177    /// Variable length with 3-digit length indicator (LLLVAR)
178    LLLVar(usize), // max length
179}
180
181/// Complete field definition
182#[allow(missing_docs)]
183#[derive(Debug, Clone, Copy, PartialEq, Eq)]
184pub struct FieldDefinition {
185    pub number: u8,
186    pub name: &'static str,
187    pub field_type: FieldType,
188    pub length: FieldLength,
189    pub description: &'static str,
190}
191
192/// Field value (parsed data)
193#[derive(Debug, Clone, PartialEq, Eq)]
194pub enum FieldValue {
195    /// String value
196    String(String),
197    /// Binary value
198    Binary(Vec<u8>),
199}
200
201impl Field {
202    /// Get field number
203    pub fn number(&self) -> u8 {
204        *self as u8
205    }
206
207    /// Get field definition
208    pub fn definition(&self) -> FieldDefinition {
209        let num = self.number();
210        let defs = get_field_definitions();
211        defs.get(num as usize).copied().unwrap_or(FieldDefinition {
212            number: num,
213            name: "Unknown",
214            field_type: FieldType::AlphaNumericSpecial,
215            length: FieldLength::LLLVar(999),
216            description: "Unknown field",
217        })
218    }
219
220    /// Create field from number
221    pub fn from_number(num: u8) -> Result<Self> {
222        match num {
223            1 => Ok(Field::SecondaryBitmap),
224            2 => Ok(Field::PrimaryAccountNumber),
225            3 => Ok(Field::ProcessingCode),
226            4 => Ok(Field::TransactionAmount),
227            5 => Ok(Field::SettlementAmount),
228            6 => Ok(Field::CardholderBillingAmount),
229            7 => Ok(Field::TransmissionDateTime),
230            8 => Ok(Field::CardholderBillingFeeAmount),
231            9 => Ok(Field::SettlementConversionRate),
232            10 => Ok(Field::CardholderBillingConversionRate),
233            11 => Ok(Field::SystemTraceAuditNumber),
234            12 => Ok(Field::LocalTransactionTime),
235            13 => Ok(Field::LocalTransactionDate),
236            14 => Ok(Field::ExpirationDate),
237            15 => Ok(Field::SettlementDate),
238            16 => Ok(Field::CurrencyConversionDate),
239            17 => Ok(Field::CaptureDate),
240            18 => Ok(Field::MerchantType),
241            19 => Ok(Field::AcquiringInstitutionCountryCode),
242            20 => Ok(Field::PANExtendedCountryCode),
243            21 => Ok(Field::ForwardingInstitutionCountryCode),
244            22 => Ok(Field::PointOfServiceEntryMode),
245            23 => Ok(Field::ApplicationPANSequenceNumber),
246            24 => Ok(Field::NetworkInternationalIdentifier),
247            25 => Ok(Field::PointOfServiceConditionCode),
248            26 => Ok(Field::PointOfServiceCaptureCode),
249            27 => Ok(Field::AuthorizingIdentificationResponseLength),
250            28 => Ok(Field::TransactionFeeAmount),
251            29 => Ok(Field::SettlementFeeAmount),
252            30 => Ok(Field::TransactionProcessingFeeAmount),
253            31 => Ok(Field::SettlementProcessingFeeAmount),
254            32 => Ok(Field::AcquiringInstitutionIdentificationCode),
255            33 => Ok(Field::ForwardingInstitutionIdentificationCode),
256            34 => Ok(Field::ExtendedPrimaryAccountNumber),
257            35 => Ok(Field::Track2Data),
258            36 => Ok(Field::Track3Data),
259            37 => Ok(Field::RetrievalReferenceNumber),
260            38 => Ok(Field::AuthorizationIdentificationResponse),
261            39 => Ok(Field::ResponseCode),
262            40 => Ok(Field::ServiceRestrictionCode),
263            41 => Ok(Field::CardAcceptorTerminalIdentification),
264            42 => Ok(Field::CardAcceptorIdentificationCode),
265            43 => Ok(Field::CardAcceptorNameLocation),
266            44 => Ok(Field::AdditionalResponseData),
267            45 => Ok(Field::Track1Data),
268            46 => Ok(Field::AdditionalDataISO),
269            47 => Ok(Field::AdditionalDataNational),
270            48 => Ok(Field::AdditionalDataPrivate),
271            49 => Ok(Field::CurrencyCodeTransaction),
272            50 => Ok(Field::CurrencyCodeSettlement),
273            51 => Ok(Field::CurrencyCodeCardholderBilling),
274            52 => Ok(Field::PersonalIdentificationNumberData),
275            53 => Ok(Field::SecurityRelatedControlInformation),
276            54 => Ok(Field::AdditionalAmounts),
277            55 => Ok(Field::ReservedISO1),
278            56 => Ok(Field::ReservedISO2),
279            57 => Ok(Field::ReservedNational1),
280            58 => Ok(Field::ReservedNational2),
281            59 => Ok(Field::ReservedNational3),
282            60 => Ok(Field::ReservedPrivate1),
283            61 => Ok(Field::ReservedPrivate2),
284            62 => Ok(Field::ReservedPrivate3),
285            63 => Ok(Field::ReservedPrivate4),
286            64 => Ok(Field::MessageAuthenticationCode),
287            65 => Ok(Field::TertiaryBitmap),
288            66 => Ok(Field::SettlementCode),
289            67 => Ok(Field::ExtendedPaymentCode),
290            68 => Ok(Field::ReceivingInstitutionCountryCode),
291            69 => Ok(Field::SettlementInstitutionCountryCode),
292            70 => Ok(Field::NetworkManagementInformationCode),
293            71 => Ok(Field::MessageNumber),
294            72 => Ok(Field::MessageNumberLast),
295            73 => Ok(Field::DateAction),
296            74 => Ok(Field::CreditsNumber),
297            75 => Ok(Field::CreditsReversalNumber),
298            76 => Ok(Field::DebitsNumber),
299            77 => Ok(Field::DebitsReversalNumber),
300            78 => Ok(Field::TransferNumber),
301            79 => Ok(Field::TransferReversalNumber),
302            80 => Ok(Field::InquiriesNumber),
303            81 => Ok(Field::AuthorizationsNumber),
304            82 => Ok(Field::CreditsProcessingFeeAmount),
305            83 => Ok(Field::CreditsTransactionFeeAmount),
306            84 => Ok(Field::DebitsProcessingFeeAmount),
307            85 => Ok(Field::DebitsTransactionFeeAmount),
308            86 => Ok(Field::CreditsAmount),
309            87 => Ok(Field::CreditsReversalAmount),
310            88 => Ok(Field::DebitsAmount),
311            89 => Ok(Field::DebitsReversalAmount),
312            90 => Ok(Field::OriginalDataElements),
313            91 => Ok(Field::FileUpdateCode),
314            92 => Ok(Field::FileSecurityCode),
315            93 => Ok(Field::ResponseIndicator),
316            94 => Ok(Field::ServiceIndicator),
317            95 => Ok(Field::ReplacementAmounts),
318            96 => Ok(Field::MessageSecurityCode),
319            97 => Ok(Field::NetSettlementAmount),
320            98 => Ok(Field::Payee),
321            99 => Ok(Field::SettlementInstitutionIdentificationCode),
322            100 => Ok(Field::ReceivingInstitutionIdentificationCode),
323            101 => Ok(Field::FileName),
324            102 => Ok(Field::AccountIdentification1),
325            103 => Ok(Field::AccountIdentification2),
326            104 => Ok(Field::TransactionDescription),
327            105 => Ok(Field::ReservedISO3),
328            106 => Ok(Field::ReservedISO4),
329            107 => Ok(Field::ReservedISO5),
330            108 => Ok(Field::ReservedISO6),
331            109 => Ok(Field::ReservedISO7),
332            110 => Ok(Field::ReservedISO8),
333            111 => Ok(Field::ReservedISO9),
334            112 => Ok(Field::ReservedNational4),
335            113 => Ok(Field::ReservedNational5),
336            114 => Ok(Field::ReservedNational6),
337            115 => Ok(Field::ReservedNational7),
338            116 => Ok(Field::ReservedNational8),
339            117 => Ok(Field::ReservedNational9),
340            118 => Ok(Field::ReservedNational10),
341            119 => Ok(Field::ReservedNational11),
342            120 => Ok(Field::ReservedPrivate5),
343            121 => Ok(Field::ReservedPrivate6),
344            122 => Ok(Field::ReservedPrivate7),
345            123 => Ok(Field::ReservedPrivate8),
346            124 => Ok(Field::InfoText),
347            125 => Ok(Field::NetworkManagementInformation),
348            126 => Ok(Field::IssuerTraceId),
349            127 => Ok(Field::ReservedPrivate9),
350            128 => Ok(Field::MessageAuthenticationCode2),
351            _ => Err(ISO8583Error::InvalidFieldNumber(num)),
352        }
353    }
354
355    /// Get all defined fields (2-128, excluding 1 and 65 which are bitmaps)
356    pub fn all() -> Vec<Self> {
357        (2..=128)
358            .filter(|&n| n != 1 && n != 65)
359            .map(|n| Self::from_number(n).unwrap())
360            .collect()
361    }
362}
363
364impl FieldValue {
365    /// Create from string
366    pub fn from_string<S: Into<String>>(s: S) -> Self {
367        Self::String(s.into())
368    }
369
370    /// Create from binary data
371    pub fn from_binary(data: Vec<u8>) -> Self {
372        Self::Binary(data)
373    }
374
375    /// Get as string reference
376    pub fn as_string(&self) -> Option<&str> {
377        match self {
378            Self::String(s) => Some(s),
379            Self::Binary(_) => None,
380        }
381    }
382
383    /// Get as binary reference
384    pub fn as_binary(&self) -> Option<&[u8]> {
385        match self {
386            Self::String(_) => None,
387            Self::Binary(b) => Some(b),
388        }
389    }
390
391    /// Convert to string (lossy for binary)
392    pub fn to_string_lossy(&self) -> String {
393        match self {
394            Self::String(s) => s.clone(),
395            Self::Binary(b) => String::from_utf8_lossy(b).to_string(),
396        }
397    }
398}
399
400impl fmt::Display for Field {
401    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
402        write!(f, "Field {} ({})", self.number(), self.definition().name)
403    }
404}
405
406impl fmt::Display for FieldValue {
407    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
408        match self {
409            Self::String(s) => write!(f, "{}", s),
410            Self::Binary(b) => write!(f, "{}", hex::encode(b)),
411        }
412    }
413}
414
415// Field definitions table (0-128, index 0 is unused, 1 and 65 are bitmaps)
416// Using const function to avoid runtime initialization
417#[allow(dead_code)]
418const fn create_field_definitions() -> [FieldDefinition; 129] {
419    // Note: This is a simplified version for const initialization
420    // In production, consider using a proc macro or build.rs for complex initialization
421    [FieldDefinition {
422        number: 0,
423        name: "Unused",
424        field_type: FieldType::Numeric,
425        length: FieldLength::Fixed(0),
426        description: "Unused field 0",
427    }; 129]
428}
429
430fn get_field_definitions() -> Vec<FieldDefinition> {
431    vec![
432        // Field 0 (unused)
433        FieldDefinition {
434            number: 0,
435            name: "Unused",
436            field_type: FieldType::Numeric,
437            length: FieldLength::Fixed(0),
438            description: "Unused field 0",
439        },
440        // Field 1 - Secondary Bitmap
441        FieldDefinition {
442            number: 1,
443            name: "Secondary Bitmap",
444            field_type: FieldType::Binary,
445            length: FieldLength::Fixed(8),
446            description: "Secondary bitmap for fields 65-128",
447        },
448        // Field 2 - Primary Account Number (PAN)
449        FieldDefinition {
450            number: 2,
451            name: "Primary Account Number",
452            field_type: FieldType::Numeric,
453            length: FieldLength::LLVar(19),
454            description: "Card number (PAN)",
455        },
456        // Field 3 - Processing Code
457        FieldDefinition {
458            number: 3,
459            name: "Processing Code",
460            field_type: FieldType::Numeric,
461            length: FieldLength::Fixed(6),
462            description: "Transaction type and account types",
463        },
464        // Field 4 - Transaction Amount
465        FieldDefinition {
466            number: 4,
467            name: "Transaction Amount",
468            field_type: FieldType::Numeric,
469            length: FieldLength::Fixed(12),
470            description: "Amount in minor currency units",
471        },
472        // Field 5 - Settlement Amount
473        FieldDefinition {
474            number: 5,
475            name: "Settlement Amount",
476            field_type: FieldType::Numeric,
477            length: FieldLength::Fixed(12),
478            description: "Settlement amount",
479        },
480        // Field 6 - Cardholder Billing Amount
481        FieldDefinition {
482            number: 6,
483            name: "Cardholder Billing Amount",
484            field_type: FieldType::Numeric,
485            length: FieldLength::Fixed(12),
486            description: "Amount billed to cardholder",
487        },
488        // Field 7 - Transmission Date & Time
489        FieldDefinition {
490            number: 7,
491            name: "Transmission Date & Time",
492            field_type: FieldType::Numeric,
493            length: FieldLength::Fixed(10),
494            description: "MMDDhhmmss",
495        },
496        // Field 8 - Cardholder Billing Fee Amount
497        FieldDefinition {
498            number: 8,
499            name: "Cardholder Billing Fee Amount",
500            field_type: FieldType::Numeric,
501            length: FieldLength::Fixed(8),
502            description: "Fee amount billed to cardholder",
503        },
504        // Field 9 - Settlement Conversion Rate
505        FieldDefinition {
506            number: 9,
507            name: "Settlement Conversion Rate",
508            field_type: FieldType::Numeric,
509            length: FieldLength::Fixed(8),
510            description: "Conversion rate for settlement",
511        },
512        // Field 10 - Cardholder Billing Conversion Rate
513        FieldDefinition {
514            number: 10,
515            name: "Cardholder Billing Conversion Rate",
516            field_type: FieldType::Numeric,
517            length: FieldLength::Fixed(8),
518            description: "Conversion rate for cardholder billing",
519        },
520        // Field 11 - System Trace Audit Number (STAN)
521        FieldDefinition {
522            number: 11,
523            name: "System Trace Audit Number",
524            field_type: FieldType::Numeric,
525            length: FieldLength::Fixed(6),
526            description: "Unique trace number for reconciliation",
527        },
528        // Field 12 - Local Transaction Time
529        FieldDefinition {
530            number: 12,
531            name: "Local Transaction Time",
532            field_type: FieldType::Numeric,
533            length: FieldLength::Fixed(6),
534            description: "hhmmss at terminal",
535        },
536        // Field 13 - Local Transaction Date
537        FieldDefinition {
538            number: 13,
539            name: "Local Transaction Date",
540            field_type: FieldType::Numeric,
541            length: FieldLength::Fixed(4),
542            description: "MMDD at terminal",
543        },
544        // Field 14 - Expiration Date
545        FieldDefinition {
546            number: 14,
547            name: "Expiration Date",
548            field_type: FieldType::Numeric,
549            length: FieldLength::Fixed(4),
550            description: "YYMM card expiration",
551        },
552        // Field 15 - Settlement Date
553        FieldDefinition {
554            number: 15,
555            name: "Settlement Date",
556            field_type: FieldType::Numeric,
557            length: FieldLength::Fixed(4),
558            description: "MMDD settlement date",
559        },
560        // Field 16 - Currency Conversion Date
561        FieldDefinition {
562            number: 16,
563            name: "Currency Conversion Date",
564            field_type: FieldType::Numeric,
565            length: FieldLength::Fixed(4),
566            description: "MMDD conversion date",
567        },
568        // Field 17 - Capture Date
569        FieldDefinition {
570            number: 17,
571            name: "Capture Date",
572            field_type: FieldType::Numeric,
573            length: FieldLength::Fixed(4),
574            description: "MMDD capture date",
575        },
576        // Field 18 - Merchant Type
577        FieldDefinition {
578            number: 18,
579            name: "Merchant Type",
580            field_type: FieldType::Numeric,
581            length: FieldLength::Fixed(4),
582            description: "Merchant Category Code (MCC)",
583        },
584        // Field 19 - Acquiring Institution Country Code
585        FieldDefinition {
586            number: 19,
587            name: "Acquiring Institution Country Code",
588            field_type: FieldType::Numeric,
589            length: FieldLength::Fixed(3),
590            description: "ISO country code of acquirer",
591        },
592        // Field 20 - PAN Extended Country Code
593        FieldDefinition {
594            number: 20,
595            name: "PAN Extended Country Code",
596            field_type: FieldType::Numeric,
597            length: FieldLength::Fixed(3),
598            description: "Country code of PAN",
599        },
600        // Field 21 - Forwarding Institution Country Code
601        FieldDefinition {
602            number: 21,
603            name: "Forwarding Institution Country Code",
604            field_type: FieldType::Numeric,
605            length: FieldLength::Fixed(3),
606            description: "Country code of forwarder",
607        },
608        // Field 22 - Point of Service Entry Mode
609        FieldDefinition {
610            number: 22,
611            name: "Point of Service Entry Mode",
612            field_type: FieldType::Numeric,
613            length: FieldLength::Fixed(3),
614            description: "How PAN was obtained (chip, swipe, manual)",
615        },
616        // Field 23 - Application PAN Sequence Number
617        FieldDefinition {
618            number: 23,
619            name: "Application PAN Sequence Number",
620            field_type: FieldType::Numeric,
621            length: FieldLength::Fixed(3),
622            description: "Card sequence number for chip cards",
623        },
624        // Field 24 - Network International Identifier
625        FieldDefinition {
626            number: 24,
627            name: "Network International Identifier",
628            field_type: FieldType::Numeric,
629            length: FieldLength::Fixed(3),
630            description: "Network function code",
631        },
632        // Field 25 - Point of Service Condition Code
633        FieldDefinition {
634            number: 25,
635            name: "Point of Service Condition Code",
636            field_type: FieldType::Numeric,
637            length: FieldLength::Fixed(2),
638            description: "Terminal condition (attended, unattended)",
639        },
640        // Field 26 - Point of Service Capture Code
641        FieldDefinition {
642            number: 26,
643            name: "Point of Service Capture Code",
644            field_type: FieldType::Numeric,
645            length: FieldLength::Fixed(2),
646            description: "Terminal capability",
647        },
648        // Field 27 - Authorizing Identification Response Length
649        FieldDefinition {
650            number: 27,
651            name: "Authorizing Identification Response Length",
652            field_type: FieldType::Numeric,
653            length: FieldLength::Fixed(1),
654            description: "Length of field 38",
655        },
656        // Field 28 - Transaction Fee Amount
657        FieldDefinition {
658            number: 28,
659            name: "Transaction Fee Amount",
660            field_type: FieldType::Numeric,
661            length: FieldLength::Fixed(8),
662            description: "Transaction fee",
663        },
664        // Field 29 - Settlement Fee Amount
665        FieldDefinition {
666            number: 29,
667            name: "Settlement Fee Amount",
668            field_type: FieldType::Numeric,
669            length: FieldLength::Fixed(8),
670            description: "Settlement fee",
671        },
672        // Field 30 - Transaction Processing Fee Amount
673        FieldDefinition {
674            number: 30,
675            name: "Transaction Processing Fee Amount",
676            field_type: FieldType::Numeric,
677            length: FieldLength::Fixed(8),
678            description: "Processing fee",
679        },
680        // Field 31 - Settlement Processing Fee Amount
681        FieldDefinition {
682            number: 31,
683            name: "Settlement Processing Fee Amount",
684            field_type: FieldType::Numeric,
685            length: FieldLength::Fixed(8),
686            description: "Settlement processing fee",
687        },
688        // Field 32 - Acquiring Institution Identification Code
689        FieldDefinition {
690            number: 32,
691            name: "Acquiring Institution Identification Code",
692            field_type: FieldType::Numeric,
693            length: FieldLength::LLVar(11),
694            description: "Acquirer ID",
695        },
696        // Field 33 - Forwarding Institution Identification Code
697        FieldDefinition {
698            number: 33,
699            name: "Forwarding Institution Identification Code",
700            field_type: FieldType::Numeric,
701            length: FieldLength::LLVar(11),
702            description: "Forwarder ID",
703        },
704        // Field 34 - Extended Primary Account Number
705        FieldDefinition {
706            number: 34,
707            name: "Extended Primary Account Number",
708            field_type: FieldType::Numeric,
709            length: FieldLength::LLVar(28),
710            description: "Extended PAN for special cases",
711        },
712        // Field 35 - Track 2 Data
713        FieldDefinition {
714            number: 35,
715            name: "Track 2 Data",
716            field_type: FieldType::Track2,
717            length: FieldLength::LLVar(37),
718            description: "Magnetic stripe track 2 data",
719        },
720        // Field 36 - Track 3 Data
721        FieldDefinition {
722            number: 36,
723            name: "Track 3 Data",
724            field_type: FieldType::Track3,
725            length: FieldLength::LLLVar(104),
726            description: "Magnetic stripe track 3 data",
727        },
728        // Field 37 - Retrieval Reference Number
729        FieldDefinition {
730            number: 37,
731            name: "Retrieval Reference Number",
732            field_type: FieldType::AlphaNumeric,
733            length: FieldLength::Fixed(12),
734            description: "Unique reference for retrieval",
735        },
736        // Field 38 - Authorization Identification Response
737        FieldDefinition {
738            number: 38,
739            name: "Authorization Identification Response",
740            field_type: FieldType::AlphaNumeric,
741            length: FieldLength::Fixed(6),
742            description: "Approval code",
743        },
744        // Field 39 - Response Code
745        FieldDefinition {
746            number: 39,
747            name: "Response Code",
748            field_type: FieldType::AlphaNumeric,
749            length: FieldLength::Fixed(2),
750            description: "Transaction result (00=approved)",
751        },
752        // Field 40 - Service Restriction Code
753        FieldDefinition {
754            number: 40,
755            name: "Service Restriction Code",
756            field_type: FieldType::AlphaNumeric,
757            length: FieldLength::Fixed(3),
758            description: "Services available on card",
759        },
760        // Field 41 - Card Acceptor Terminal Identification
761        FieldDefinition {
762            number: 41,
763            name: "Card Acceptor Terminal Identification",
764            field_type: FieldType::AlphaNumericSpecial,
765            length: FieldLength::Fixed(8),
766            description: "Terminal ID",
767        },
768        // Field 42 - Card Acceptor Identification Code
769        FieldDefinition {
770            number: 42,
771            name: "Card Acceptor Identification Code",
772            field_type: FieldType::AlphaNumericSpecial,
773            length: FieldLength::Fixed(15),
774            description: "Merchant ID",
775        },
776        // Field 43 - Card Acceptor Name/Location
777        FieldDefinition {
778            number: 43,
779            name: "Card Acceptor Name/Location",
780            field_type: FieldType::AlphaNumericSpecial,
781            length: FieldLength::Fixed(40),
782            description: "Merchant name and location",
783        },
784        // Field 44 - Additional Response Data
785        FieldDefinition {
786            number: 44,
787            name: "Additional Response Data",
788            field_type: FieldType::AlphaNumericSpecial,
789            length: FieldLength::LLVar(25),
790            description: "Additional response information",
791        },
792        // Field 45 - Track 1 Data
793        FieldDefinition {
794            number: 45,
795            name: "Track 1 Data",
796            field_type: FieldType::AlphaNumericSpecial,
797            length: FieldLength::LLVar(76),
798            description: "Magnetic stripe track 1 data",
799        },
800        // Field 46 - Additional Data (ISO)
801        FieldDefinition {
802            number: 46,
803            name: "Additional Data (ISO)",
804            field_type: FieldType::AlphaNumericSpecial,
805            length: FieldLength::LLLVar(999),
806            description: "ISO reserved additional data",
807        },
808        // Field 47 - Additional Data (National)
809        FieldDefinition {
810            number: 47,
811            name: "Additional Data (National)",
812            field_type: FieldType::AlphaNumericSpecial,
813            length: FieldLength::LLLVar(999),
814            description: "National use additional data",
815        },
816        // Field 48 - Additional Data (Private)
817        FieldDefinition {
818            number: 48,
819            name: "Additional Data (Private)",
820            field_type: FieldType::AlphaNumericSpecial,
821            length: FieldLength::LLLVar(999),
822            description: "Private use additional data",
823        },
824        // Field 49 - Currency Code, Transaction
825        FieldDefinition {
826            number: 49,
827            name: "Currency Code, Transaction",
828            field_type: FieldType::AlphaNumeric,
829            length: FieldLength::Fixed(3),
830            description: "ISO 4217 currency code",
831        },
832        // Field 50 - Currency Code, Settlement
833        FieldDefinition {
834            number: 50,
835            name: "Currency Code, Settlement",
836            field_type: FieldType::AlphaNumeric,
837            length: FieldLength::Fixed(3),
838            description: "Settlement currency code",
839        },
840        // Field 51 - Currency Code, Cardholder Billing
841        FieldDefinition {
842            number: 51,
843            name: "Currency Code, Cardholder Billing",
844            field_type: FieldType::AlphaNumeric,
845            length: FieldLength::Fixed(3),
846            description: "Cardholder billing currency",
847        },
848        // Field 52 - Personal Identification Number Data
849        FieldDefinition {
850            number: 52,
851            name: "Personal Identification Number Data",
852            field_type: FieldType::Binary,
853            length: FieldLength::Fixed(8),
854            description: "Encrypted PIN block",
855        },
856        // Field 53 - Security Related Control Information
857        FieldDefinition {
858            number: 53,
859            name: "Security Related Control Information",
860            field_type: FieldType::Numeric,
861            length: FieldLength::Fixed(16),
862            description: "Security control information",
863        },
864        // Field 54 - Additional Amounts
865        FieldDefinition {
866            number: 54,
867            name: "Additional Amounts",
868            field_type: FieldType::AlphaNumericSpecial,
869            length: FieldLength::LLLVar(120),
870            description: "Additional amount fields",
871        },
872        // Fields 55-64 (continued in next part due to length)
873        // Field 55 - Reserved ISO
874        FieldDefinition {
875            number: 55,
876            name: "Reserved ISO",
877            field_type: FieldType::AlphaNumericSpecial,
878            length: FieldLength::LLLVar(999),
879            description: "Reserved for ISO use",
880        },
881        // Field 56-128 definitions would continue...
882        // For brevity, I'll add a few more key fields and then continue in the next file
883
884        // Field 64 - Message Authentication Code
885        FieldDefinition {
886            number: 64,
887            name: "Message Authentication Code",
888            field_type: FieldType::Binary,
889            length: FieldLength::Fixed(8),
890            description: "MAC for message integrity",
891        },
892        // Field 65 - Tertiary Bitmap (extended fields indicator)
893        FieldDefinition {
894            number: 65,
895            name: "Tertiary Bitmap",
896            field_type: FieldType::Binary,
897            length: FieldLength::Fixed(8),
898            description: "Tertiary bitmap for fields 129-192",
899        },
900        // Fields 66-128
901        FieldDefinition {
902            number: 66,
903            name: "Settlement Code",
904            field_type: FieldType::Numeric,
905            length: FieldLength::Fixed(1),
906            description: "Settlement code",
907        },
908        FieldDefinition {
909            number: 67,
910            name: "Extended Payment Code",
911            field_type: FieldType::Numeric,
912            length: FieldLength::Fixed(2),
913            description: "Extended payment code",
914        },
915        FieldDefinition {
916            number: 68,
917            name: "Receiving Institution Country Code",
918            field_type: FieldType::Numeric,
919            length: FieldLength::Fixed(3),
920            description: "Country code of receiver",
921        },
922        FieldDefinition {
923            number: 69,
924            name: "Settlement Institution Country Code",
925            field_type: FieldType::Numeric,
926            length: FieldLength::Fixed(3),
927            description: "Country code of settler",
928        },
929        FieldDefinition {
930            number: 70,
931            name: "Network Management Information Code",
932            field_type: FieldType::Numeric,
933            length: FieldLength::Fixed(3),
934            description: "Network management code",
935        },
936        FieldDefinition {
937            number: 71,
938            name: "Message Number",
939            field_type: FieldType::Numeric,
940            length: FieldLength::Fixed(4),
941            description: "Message sequence number",
942        },
943        FieldDefinition {
944            number: 72,
945            name: "Message Number Last",
946            field_type: FieldType::Numeric,
947            length: FieldLength::Fixed(4),
948            description: "Last message number",
949        },
950        FieldDefinition {
951            number: 73,
952            name: "Date Action",
953            field_type: FieldType::Numeric,
954            length: FieldLength::Fixed(6),
955            description: "YYMMDD action date",
956        },
957        FieldDefinition {
958            number: 74,
959            name: "Credits Number",
960            field_type: FieldType::Numeric,
961            length: FieldLength::Fixed(10),
962            description: "Number of credits",
963        },
964        FieldDefinition {
965            number: 75,
966            name: "Credits Reversal Number",
967            field_type: FieldType::Numeric,
968            length: FieldLength::Fixed(10),
969            description: "Number of credit reversals",
970        },
971        FieldDefinition {
972            number: 76,
973            name: "Debits Number",
974            field_type: FieldType::Numeric,
975            length: FieldLength::Fixed(10),
976            description: "Number of debits",
977        },
978        FieldDefinition {
979            number: 77,
980            name: "Debits Reversal Number",
981            field_type: FieldType::Numeric,
982            length: FieldLength::Fixed(10),
983            description: "Number of debit reversals",
984        },
985        FieldDefinition {
986            number: 78,
987            name: "Transfer Number",
988            field_type: FieldType::Numeric,
989            length: FieldLength::Fixed(10),
990            description: "Number of transfers",
991        },
992        FieldDefinition {
993            number: 79,
994            name: "Transfer Reversal Number",
995            field_type: FieldType::Numeric,
996            length: FieldLength::Fixed(10),
997            description: "Number of transfer reversals",
998        },
999        FieldDefinition {
1000            number: 80,
1001            name: "Inquiries Number",
1002            field_type: FieldType::Numeric,
1003            length: FieldLength::Fixed(10),
1004            description: "Number of inquiries",
1005        },
1006        FieldDefinition {
1007            number: 81,
1008            name: "Authorizations Number",
1009            field_type: FieldType::Numeric,
1010            length: FieldLength::Fixed(10),
1011            description: "Number of authorizations",
1012        },
1013        FieldDefinition {
1014            number: 82,
1015            name: "Credits Processing Fee Amount",
1016            field_type: FieldType::Numeric,
1017            length: FieldLength::Fixed(12),
1018            description: "Credits processing fee",
1019        },
1020        FieldDefinition {
1021            number: 83,
1022            name: "Credits Transaction Fee Amount",
1023            field_type: FieldType::Numeric,
1024            length: FieldLength::Fixed(12),
1025            description: "Credits transaction fee",
1026        },
1027        FieldDefinition {
1028            number: 84,
1029            name: "Debits Processing Fee Amount",
1030            field_type: FieldType::Numeric,
1031            length: FieldLength::Fixed(12),
1032            description: "Debits processing fee",
1033        },
1034        FieldDefinition {
1035            number: 85,
1036            name: "Debits Transaction Fee Amount",
1037            field_type: FieldType::Numeric,
1038            length: FieldLength::Fixed(12),
1039            description: "Debits transaction fee",
1040        },
1041        FieldDefinition {
1042            number: 86,
1043            name: "Credits Amount",
1044            field_type: FieldType::Numeric,
1045            length: FieldLength::Fixed(16),
1046            description: "Total credits amount",
1047        },
1048        FieldDefinition {
1049            number: 87,
1050            name: "Credits Reversal Amount",
1051            field_type: FieldType::Numeric,
1052            length: FieldLength::Fixed(16),
1053            description: "Total credits reversal amount",
1054        },
1055        FieldDefinition {
1056            number: 88,
1057            name: "Debits Amount",
1058            field_type: FieldType::Numeric,
1059            length: FieldLength::Fixed(16),
1060            description: "Total debits amount",
1061        },
1062        FieldDefinition {
1063            number: 89,
1064            name: "Debits Reversal Amount",
1065            field_type: FieldType::Numeric,
1066            length: FieldLength::Fixed(16),
1067            description: "Total debits reversal amount",
1068        },
1069        FieldDefinition {
1070            number: 90,
1071            name: "Original Data Elements",
1072            field_type: FieldType::Numeric,
1073            length: FieldLength::Fixed(42),
1074            description: "Original transaction data",
1075        },
1076        FieldDefinition {
1077            number: 91,
1078            name: "File Update Code",
1079            field_type: FieldType::AlphaNumeric,
1080            length: FieldLength::Fixed(1),
1081            description: "File action code",
1082        },
1083        FieldDefinition {
1084            number: 92,
1085            name: "File Security Code",
1086            field_type: FieldType::AlphaNumeric,
1087            length: FieldLength::Fixed(2),
1088            description: "File security code",
1089        },
1090        FieldDefinition {
1091            number: 93,
1092            name: "Response Indicator",
1093            field_type: FieldType::AlphaNumeric,
1094            length: FieldLength::Fixed(5),
1095            description: "Response routing indicator",
1096        },
1097        FieldDefinition {
1098            number: 94,
1099            name: "Service Indicator",
1100            field_type: FieldType::AlphaNumeric,
1101            length: FieldLength::Fixed(7),
1102            description: "Service indicator",
1103        },
1104        FieldDefinition {
1105            number: 95,
1106            name: "Replacement Amounts",
1107            field_type: FieldType::AlphaNumeric,
1108            length: FieldLength::Fixed(42),
1109            description: "Replacement amounts",
1110        },
1111        FieldDefinition {
1112            number: 96,
1113            name: "Message Security Code",
1114            field_type: FieldType::Binary,
1115            length: FieldLength::Fixed(8),
1116            description: "Message security code",
1117        },
1118        FieldDefinition {
1119            number: 97,
1120            name: "Net Settlement Amount",
1121            field_type: FieldType::Numeric,
1122            length: FieldLength::Fixed(16),
1123            description: "Net settlement amount",
1124        },
1125        FieldDefinition {
1126            number: 98,
1127            name: "Payee",
1128            field_type: FieldType::AlphaNumericSpecial,
1129            length: FieldLength::Fixed(25),
1130            description: "Payee information",
1131        },
1132        FieldDefinition {
1133            number: 99,
1134            name: "Settlement Institution Identification Code",
1135            field_type: FieldType::Numeric,
1136            length: FieldLength::LLVar(11),
1137            description: "Settlement institution ID",
1138        },
1139        FieldDefinition {
1140            number: 100,
1141            name: "Receiving Institution Identification Code",
1142            field_type: FieldType::Numeric,
1143            length: FieldLength::LLVar(11),
1144            description: "Receiving institution ID",
1145        },
1146        FieldDefinition {
1147            number: 101,
1148            name: "File Name",
1149            field_type: FieldType::AlphaNumericSpecial,
1150            length: FieldLength::LLVar(17),
1151            description: "File name",
1152        },
1153        FieldDefinition {
1154            number: 102,
1155            name: "Account Identification 1",
1156            field_type: FieldType::AlphaNumericSpecial,
1157            length: FieldLength::LLVar(28),
1158            description: "Account identification 1",
1159        },
1160        FieldDefinition {
1161            number: 103,
1162            name: "Account Identification 2",
1163            field_type: FieldType::AlphaNumericSpecial,
1164            length: FieldLength::LLVar(28),
1165            description: "Account identification 2",
1166        },
1167        FieldDefinition {
1168            number: 104,
1169            name: "Transaction Description",
1170            field_type: FieldType::AlphaNumericSpecial,
1171            length: FieldLength::LLLVar(100),
1172            description: "Transaction description",
1173        },
1174        FieldDefinition {
1175            number: 105,
1176            name: "Reserved ISO 3",
1177            field_type: FieldType::AlphaNumericSpecial,
1178            length: FieldLength::LLLVar(999),
1179            description: "Reserved for ISO use",
1180        },
1181        FieldDefinition {
1182            number: 106,
1183            name: "Reserved ISO 4",
1184            field_type: FieldType::AlphaNumericSpecial,
1185            length: FieldLength::LLLVar(999),
1186            description: "Reserved for ISO use",
1187        },
1188        FieldDefinition {
1189            number: 107,
1190            name: "Reserved ISO 5",
1191            field_type: FieldType::AlphaNumericSpecial,
1192            length: FieldLength::LLLVar(999),
1193            description: "Reserved for ISO use",
1194        },
1195        FieldDefinition {
1196            number: 108,
1197            name: "Reserved ISO 6",
1198            field_type: FieldType::AlphaNumericSpecial,
1199            length: FieldLength::LLLVar(999),
1200            description: "Reserved for ISO use",
1201        },
1202        FieldDefinition {
1203            number: 109,
1204            name: "Reserved ISO 7",
1205            field_type: FieldType::AlphaNumericSpecial,
1206            length: FieldLength::LLLVar(999),
1207            description: "Reserved for ISO use",
1208        },
1209        FieldDefinition {
1210            number: 110,
1211            name: "Reserved ISO 8",
1212            field_type: FieldType::AlphaNumericSpecial,
1213            length: FieldLength::LLLVar(999),
1214            description: "Reserved for ISO use",
1215        },
1216        FieldDefinition {
1217            number: 111,
1218            name: "Reserved ISO 9",
1219            field_type: FieldType::AlphaNumericSpecial,
1220            length: FieldLength::LLLVar(999),
1221            description: "Reserved for ISO use",
1222        },
1223        FieldDefinition {
1224            number: 112,
1225            name: "Reserved National 4",
1226            field_type: FieldType::AlphaNumericSpecial,
1227            length: FieldLength::LLLVar(999),
1228            description: "Reserved for national use",
1229        },
1230        FieldDefinition {
1231            number: 113,
1232            name: "Reserved National 5",
1233            field_type: FieldType::AlphaNumericSpecial,
1234            length: FieldLength::LLLVar(999),
1235            description: "Reserved for national use",
1236        },
1237        FieldDefinition {
1238            number: 114,
1239            name: "Reserved National 6",
1240            field_type: FieldType::AlphaNumericSpecial,
1241            length: FieldLength::LLLVar(999),
1242            description: "Reserved for national use",
1243        },
1244        FieldDefinition {
1245            number: 115,
1246            name: "Reserved National 7",
1247            field_type: FieldType::AlphaNumericSpecial,
1248            length: FieldLength::LLLVar(999),
1249            description: "Reserved for national use",
1250        },
1251        FieldDefinition {
1252            number: 116,
1253            name: "Reserved National 8",
1254            field_type: FieldType::AlphaNumericSpecial,
1255            length: FieldLength::LLLVar(999),
1256            description: "Reserved for national use",
1257        },
1258        FieldDefinition {
1259            number: 117,
1260            name: "Reserved National 9",
1261            field_type: FieldType::AlphaNumericSpecial,
1262            length: FieldLength::LLLVar(999),
1263            description: "Reserved for national use",
1264        },
1265        FieldDefinition {
1266            number: 118,
1267            name: "Reserved National 10",
1268            field_type: FieldType::AlphaNumericSpecial,
1269            length: FieldLength::LLLVar(999),
1270            description: "Reserved for national use",
1271        },
1272        FieldDefinition {
1273            number: 119,
1274            name: "Reserved National 11",
1275            field_type: FieldType::AlphaNumericSpecial,
1276            length: FieldLength::LLLVar(999),
1277            description: "Reserved for national use",
1278        },
1279        FieldDefinition {
1280            number: 120,
1281            name: "Reserved Private 5",
1282            field_type: FieldType::AlphaNumericSpecial,
1283            length: FieldLength::LLLVar(999),
1284            description: "Reserved for private use",
1285        },
1286        FieldDefinition {
1287            number: 121,
1288            name: "Reserved Private 6",
1289            field_type: FieldType::AlphaNumericSpecial,
1290            length: FieldLength::LLLVar(999),
1291            description: "Reserved for private use",
1292        },
1293        FieldDefinition {
1294            number: 122,
1295            name: "Reserved Private 7",
1296            field_type: FieldType::AlphaNumericSpecial,
1297            length: FieldLength::LLLVar(999),
1298            description: "Reserved for private use",
1299        },
1300        FieldDefinition {
1301            number: 123,
1302            name: "Reserved Private 8",
1303            field_type: FieldType::AlphaNumericSpecial,
1304            length: FieldLength::LLLVar(999),
1305            description: "Reserved for private use",
1306        },
1307        FieldDefinition {
1308            number: 124,
1309            name: "Info Text",
1310            field_type: FieldType::AlphaNumericSpecial,
1311            length: FieldLength::LLLVar(255),
1312            description: "Information text",
1313        },
1314        FieldDefinition {
1315            number: 125,
1316            name: "Network Management Information",
1317            field_type: FieldType::AlphaNumericSpecial,
1318            length: FieldLength::LLLVar(50),
1319            description: "Network management info",
1320        },
1321        FieldDefinition {
1322            number: 126,
1323            name: "Issuer Trace Id",
1324            field_type: FieldType::AlphaNumericSpecial,
1325            length: FieldLength::LLLVar(6),
1326            description: "Issuer trace identifier",
1327        },
1328        FieldDefinition {
1329            number: 127,
1330            name: "Reserved Private 9",
1331            field_type: FieldType::AlphaNumericSpecial,
1332            length: FieldLength::LLLVar(999),
1333            description: "Reserved for private use",
1334        },
1335        FieldDefinition {
1336            number: 128,
1337            name: "Message Authentication Code 2",
1338            field_type: FieldType::Binary,
1339            length: FieldLength::Fixed(8),
1340            description: "Secondary MAC",
1341        },
1342    ]
1343}
1344
1345impl FieldDefinition {
1346    /// Get field definition by number
1347    pub fn get(number: u8) -> Option<Self> {
1348        if number > 128 {
1349            return None;
1350        }
1351        let defs = get_field_definitions();
1352        Some(defs[number as usize])
1353    }
1354}
1355
1356#[cfg(test)]
1357mod tests {
1358    use super::*;
1359
1360    #[test]
1361    fn test_field_from_number() {
1362        let field = Field::from_number(2).unwrap();
1363        assert_eq!(field, Field::PrimaryAccountNumber);
1364        assert_eq!(field.number(), 2);
1365    }
1366
1367    #[test]
1368    fn test_field_definition() {
1369        let field = Field::PrimaryAccountNumber;
1370        let def = field.definition();
1371        assert_eq!(def.number, 2);
1372        assert_eq!(def.name, "Primary Account Number");
1373        assert_eq!(def.field_type, FieldType::Numeric);
1374    }
1375
1376    #[test]
1377    fn test_field_value() {
1378        let value = FieldValue::from_string("4111111111111111");
1379        assert_eq!(value.as_string(), Some("4111111111111111"));
1380        assert_eq!(value.to_string_lossy(), "4111111111111111");
1381    }
1382
1383    #[test]
1384    fn test_invalid_field_number() {
1385        assert!(Field::from_number(0).is_err());
1386        assert!(Field::from_number(129).is_err());
1387    }
1388}