Microsoft Updater Application Block 1.4.2 IValidator介面設計 [翻譯]

來源:互聯網
上載者:User
Microsoft Updater Application Block IValidator介面設計



譯者:Tony Qu

IValidator介面使得通過實現驗證器擴充Updater Application Block成為可能。

問題描述

為了允許程式員把自己的驗證器實現插入到Updater Application Block中,一個用於定義驗證器類型的公用介面必須被顯露出來,驗證器類型將被manifest工具使用。

設計目的、權衡和問題

Updater Application Block的開發人員認識到以下一些目標、權衡和問題

1. Updater Application Block應該有足夠的靈活性來支援各式各樣的驗證技術和密鑰。

2. 驗證器應該既能夠產生簽名,又能夠驗證這些簽名。

3. 雖然大多數加密技術內部包含對位元組數組或流的修改,但這決定了驗證器必須以字串類型暴露所有的密鑰和簽名。這使得驗證基於xml的manifest檔案中的簽名變得更加簡單,並且給了開發人員在選擇驗證演算法方面更多的自由。

解決方案

IValidator介面形成的構建驗證器類的基礎,它暴露出三個方法:

1. Init —— 用於初始化驗證器

2. Validate —— 重載方法,該方法用於驗證一個檔案或一個xml節點

3. Sign —— 重載方法,用於為一個檔案或xml節點產生簽名。

具體實現

IValidator介面位於Microsoft.ApplicationBlocks.ApplicationUpdater.Interfaces命名空間。

[VB.NET]
Public Interface IValidatorInterface IValidator

    Inherits IDisposable


  Sub Init()Sub Init (ByVal config As XmlNode)


  Function Validate()Function Validate (ByVal filePath As String, ByVal signature As String) _

      As Boolean


  Function Validate()Function Validate (ByVal xml As XmlNode, ByVal signature As String) _

      As Boolean


  Function Sign()Function Sign (ByVal filePath As String, ByVal key As String) As String


  Function Sign()Function Sign (ByVal xml As XmlNode, ByVal key As String) As String


End Interface

[C#]
public interface IValidator : IDisposable 

{

  void Init( XmlNode config );

  bool Validate( string filePath, string signature );

  bool Validate( XmlNode xml, string signature );

  string Sign( string filePath, string key );

  string Sign( XmlNode xml, string key );

}

暴露出來的IValidator介面的方法將在下面討論:

1. Init方法用於初始化驗證器,它從應用程式升級設定檔中讀取<validator>配置節。在大多數情況下,該配置節將包含一個<key>元素,該元素提供用於簽名產生和驗證的加密金鑰。

2. Validate方法被重載,使其可以接受一個string類型或一個XmlNode類型的參數作為驗證內容。在兩個重載函數,另一個參數是一個包含簽名的string值,傳回值是一個反映驗證是否成功的bool值。

3. Sign方法被重載,使其接受一個包含檔案路徑的字串或者包含<ServerApplicationInfo>節點資訊的XmlNode值。兩個重載函數的第二個參數是一個包含密鑰的字串,該密鑰用於產生簽名。該方法返回一個包含簽名的字串。

注意:由於IValidator介面派生與IDisposable介面,任何一個驗證器類還必須實現IDisposable介面,該介面提供一種通用而有效釋放資源的模式。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.